Box2D Cannon Game With Stars
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CGame Class Reference

The game class. More...

#include <Game.h>

Inheritance diagram for CGame:
CCommon

Public Member Functions

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

Private Member Functions

void LoadSounds ()
 Load sounds. More...
 
void BeginGame ()
 Begin playing the game. More...
 
void KeyboardHandler ()
 The keyboard handler. More...
 
void RenderFrame ()
 Render an animation frame. More...
 
void CreateObjects ()
 Create game objects. More...
 
void DrawWinLose (UINT, eGameState, UINT)
 Draw win/lose text. More...
 

Private Attributes

CHeadsUpDisplaym_pHud = nullptr
 The HUD.
 
CCannonm_pCannon = nullptr
 The cannon.
 
eGameState m_eGameState = eGameState::Size
 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 CRendererm_pRenderer = nullptr
 Pointer to Render World.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.

 
static LParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static bool m_bEasterEgg = false
 Easter egg!
 

Detailed Description

The game class.

Constructor & Destructor Documentation

◆ CGame()

CGame::CGame ( )

Constructor.

Create a heads-up display.

◆ ~CGame()

CGame::~CGame ( )

Destructor.

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

Begin playing the game.

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.

◆ CreateObjects()

void CGame::CreateObjects ( )
private

Create game objects.

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

◆ DrawWinLose()

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

Draw win/lose text.

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.

◆ Initialize()

void CGame::Initialize ( )

Initialize the game.

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

◆ KeyboardHandler()

void CGame::KeyboardHandler ( )
private

The keyboard handler.

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

◆ LoadSounds()

void CGame::LoadSounds ( )
private

Load sounds.

Initialize the audio player and load game sounds.

◆ ProcessFrame()

void CGame::ProcessFrame ( )

Process an animation frame.

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.

◆ Release()

void CGame::Release ( )

Release the renderer.

Release all of the DirectX12 objects by deleting the renderer.

◆ RenderFrame()

void CGame::RenderFrame ( )
private

Render an animation frame.

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.