![]() |
Box2D Cannon Game With Stars
Game Physics with a 2D Physics Engine
|
The game class.
#include <Game.h>


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 | |
| CHeadsUpDisplay * | m_pHud = nullptr |
| The HUD. | |
| CCannon * | m_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 CObjectManager * | m_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! | |
| CGame::CGame | ( | ) |
Create a heads-up display.
| 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.
|
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.


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


|
private |
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 Render World and the object manager, load images and sounds, start the timer, and begin the game.


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


|
private |
Load the sounds for this game.

|
private |
Load the sprites for this game.

| 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.


|
private |
Take action appropriate to the current game state.


|
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.


| void CGame::Release | ( | ) |
Release all of the DirectX12 objects by deleting the renderer.

|
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.

