![]() |
Box2D Cannon Game With Stars
Ian Parberry's "Introduction to Game Physics"
|
The game class. More...
#include <Game.h>
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 | |
CHeadsUpDisplay * | m_pHud = nullptr |
The HUD. | |
CCannon * | m_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 b2World * | m_pPhysicsWorld = nullptr |
Pointer to Box2D Physics World. | |
static CRenderer * | m_pRenderer = nullptr |
Pointer to Render World. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to object manager. | |
static LParticleEngine2D * | m_pParticleEngine = nullptr |
Pointer to particle engine. | |
static bool | m_bEasterEgg = false |
Easter egg! | |
The game class.
CGame::CGame | ( | ) |
Constructor.
Create a heads-up display.
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.
|
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.
|
private |
Create game objects.
Ask the object manager to create the game objects and ask the cannon and HUD to create themselves.
|
private |
Draw win/lose text.
Tell the player whether they've won or lost by plastering a text banner across the screen.
n | Number of shots fired. |
s | The game state, which tells whether the player has won or lost. |
t | Time to completion, in seconds. |
void CGame::Initialize | ( | ) |
Initialize the game.
Initialize Render World and the object manager, load images and sounds, start the timer, and begin the game.
|
private |
The keyboard handler.
Poll the keyboard state and respond to the key presses that happened since the last frame.
|
private |
Load sounds.
Initialize the audio player and load game sounds.
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.
void CGame::Release | ( | ) |
Release the renderer.
Release all of the DirectX12 objects by deleting the renderer.
|
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.