Box2D Cannon Game With Stars
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CGame Class Reference

The game class.

#include <Game.h>

Inheritance diagram for CGame:
Collaboration diagram for CGame:

Public Member Functions

 CGame ()
 Constructor.
 
 ~CGame ()
 Destructor.
 
void Initialize ()
 Initialize the game.
 
void ProcessFrame ()
 Process an animation frame.
 
void Release ()
 Release the renderer.
 

Private Member Functions

void LoadSprites ()
 Start loading sprites.
 
void LoadSounds ()
 Start loading sounds.
 
void BeginGame ()
 Begin playing the game.
 
void KeyboardHandler ()
 The keyboard handler.
 
void RenderFrame ()
 Render an animation frame.
 
void ProcessState ()
 Process game state.
 
void ProcessWinLose ()
 Process whether player has won or lost.
 
void CreateObjects ()
 Create game objects.
 
void DrawWinLose (UINT, eGameState, UINT)
 Draw win/lose text.
 

Private Attributes

CHeadsUpDisplaym_pHud = nullptr
 The HUD.
 
CCannonm_pCannon = nullptr
 The cannon.
 
Sage::CEventTimer * m_pTickTimer = nullptr
 Clock tick timer.
 
eGameState m_eGameState = eGameState::Loading
 Current game state.
 
float m_fLevelStartTime = 0
 Level start time.
 
float m_fLevelEndTime = 0
 Level end time.
 
CMyListener m_cContactListener
 Contact listener.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CBox2DRenderer * m_pRenderer = nullptr
 Pointer to Render World.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.

 
static Sage::CParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static eDrawMode m_eDrawMode = eDrawMode::Sprites
 Draw mode.
 
static bool m_bEasterEgg = false
 Easter egg!
 

Constructor & Destructor Documentation

◆ CGame()

CGame::CGame ( )

Create a heads-up display.

◆ ~CGame()

CGame::~CGame ( )

Delete the HUD, cannon, and stopwatch created in the constructor. Call Render World's Release function to do the required Direct3D cleanup, then delete Render World and the object manager. Also delete Physics World, which MUST be deleted after the object manager because of way things are set up.

Member Function Documentation

◆ BeginGame()

void CGame::BeginGame ( )
private

Clear any old objects out of the object manager and create the edges of the game world, which correspond to the edges of the window. Clear the HUD, set the initial game state, and start the stopwatch.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateObjects()

void CGame::CreateObjects ( )
private

Ask the object manager to create the game objects and ask the cannon and HUD to create themselves.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawWinLose()

void CGame::DrawWinLose ( UINT n,
eGameState s,
UINT t )
private

Tell the player whether they've won or lost by plastering a text banner across the screen.

Parameters
nNumber of shots fired.
sThe game state, which tells whether the player has won or lost.
tTime to completion, in seconds.
Here is the caller graph for this function:

◆ Initialize()

void CGame::Initialize ( )

Initialize Render World and the object manager, load images and sounds, start the timer, and begin the game.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeyboardHandler()

void CGame::KeyboardHandler ( )
private

Poll the keyboard state and respond to the key presses that happened since the last frame.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSounds()

void CGame::LoadSounds ( )
private

Load the sounds for this game.

Here is the caller graph for this function:

◆ LoadSprites()

void CGame::LoadSprites ( )
private

Load the sprites for this game.

Here is the caller graph for this function:

◆ ProcessFrame()

void CGame::ProcessFrame ( )

Handle keyboard input, move the game objects and render them in their new positions and orientations. Notify the timer of the start and end of the frame so that it can calculate frame time. Cool the cannon down, move and draw particles, play object collision sounds, play a ticking sound for the stopwatch and do the right thing if the player has won or lost.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessState()

void CGame::ProcessState ( )
private

Take action appropriate to the current game state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessWinLose()

void CGame::ProcessWinLose ( )
private

Determine whether the player has won or lost, and if so, change the game state, play the appropriate sound, and record the level end time.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Release()

void CGame::Release ( )

Release all of the DirectX12 objects by deleting the renderer.

Here is the caller graph for this function:

◆ RenderFrame()

void CGame::RenderFrame ( )
private

Ask the object manager to draw the game objects. RenderWorld is notified of the start and end of the frame so that it can let Direct3D do its pipelining jiggery-pokery. Draw the smoke particles from the cannon, the HUD, and any win/lose messages that are appropriate.

Here is the call graph for this function:
Here is the caller graph for this function: