![]() |
The Pinball Game
Game Physics with Bespoke Code
|
The game class. More...
#include <Game.h>


Public Member Functions | |
| ~CGame () | |
| Destructor. | |
| void | Initialize () |
| Initialize the game. | |
| void | ProcessFrame () |
| Process an animation frame. | |
| void | Release () |
| Release the renderer. | |
Private Member Functions | |
| void | SetScoreDesc () |
| Set score descriptor. | |
| void | LoadSprites () |
| Load sprites. | |
| void | LoadSounds () |
| Load sounds. | |
| void | BeginGame () |
| Begin playing the game. | |
| void | KeyboardHandler () |
| The keyboard handler. | |
| void | DrawFrameRateText (const XMVECTORF32 &) |
| Draw frame rate text to screen. | |
| void | RenderFrame () |
| Render an animation frame. | |
| void | ProcessState () |
| Process game state. | |
| void | Launch () |
| Create and launch a ball. | |
Private Attributes | |
| bool | m_bDrawFrameRate = false |
| Draw the frame rate. | |
| eGameState | m_eGameState = eGameState::Loading |
| Game state. | |
| CObjectManager * | m_pObjectManager = nullptr |
| Pointer to object manager. | |
| Sage::CSpriteDesc2D | m_cClipDesc0 |
| Sprite descriptor for clip 0. | |
| Sage::CSpriteDesc2D | m_cClipDesc1 |
| Sprite descriptor for clip 0. | |
| Sage::CSpriteDesc2D | m_cScoreDesc [NUMSCOREDIGITS] |
| Sprite descriptors for score digits. | |
| Shapes::CDynamicCircle * | m_pCurBallShape = nullptr |
| Pointer to current ball shape. | |
Static Private Attributes | |
| static const UINT | NUMSCOREDIGITS = 6 |
| Number of digits in score. | |
Additional Inherited Members | |
Static Protected Attributes inherited from CCommon | |
| static Sage::CSpriteRenderer * | m_pRenderer = nullptr |
| Pointer to the renderer. | |
| static CObjectManager * | m_pObjectManager = nullptr |
| Pointer to the object manager. | |
| static UINT | m_nMIterations = 4 |
| Number of motion iterations. | |
| static UINT | m_nCIterations = 1 |
| Number of collision iterations. | |
| static float | m_fFrequency = 60.0f*m_nMIterations |
| Frequency, number of physics iterations per second. | |
| static eDrawMode | m_eDrawMode = eDrawMode::Background |
| Draw mode. | |
| static bool | m_bBallInPlay = false |
| Is there a ball currently in play? | |
| static UINT | m_nScore = 0 |
| Current score. | |
The game class is the object-oriented implementation of the game. This class must contain the following public member functions. Initialize() does initialization and will be run exactly once at the start of the game. ProcessFrame() will be called once per frame to create and render the next animation frame. Release() will be called at game exit but before any destructors are run.
|
private |
Create the edges of the world and some shapes.


|
private |
Draw the current frame rate to a hard-coded position in the window. The frame rate will be drawn in a hard-coded position using the font specified in GameSettings.xml.
| color | Text color from Colors::. |

| void CGame::Initialize | ( | ) |
Initialize the game as follows. Set the timer. Initialize game variables. Create the renderer and the object manager. Load images and sounds from files.


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


|
private |
If there is no ball, create one and place it in the chute ready for launch. Otherwise, assuming that this has been done and the ball is ready to launch, then apply a vertical impulse to it. Add a little bit of randomness to that impulse so that it behaves slightly differently each time.


|
private |
Create a media list Sage::CMediaList of eSound. For each sound, insert into the media list a pair consisting of an instance of the sound enumerated type eSound and the corresponding string used in the name field in a <sound> tag in GameSettings.xml. Pass the media list to the sound manager for loading.

|
private |
Create a media list Sage::CMediaList of eSprite. For each sprite, insert into the media list a pair consisting of an instance of the sprite enumerated type eSprite and the corresponding string used in the name field in a <sprite> tag in GameSettings.xml. Pass the media list to the renderer for loading.

| void CGame::ProcessFrame | ( | ) |
Handle keyboard input, move the game objects and render them in their new positions and orientations. Notify the audio player at the start of each frame so that it can prevent multiple copies of a sound from starting on the same frame.


|
private |
Process any changes to the current game state. If the game is in state eGameState::Loading and both the renderer and the sound manager have finished loading (which may or may not be multithreaded), then begin the game.


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

|
private |
Ask the object manager to draw the game objects. The renderer is notified of the start and end of the frame so that it can let Direct3D do its pipelining jiggery-pokery. Finally, draw the score and the clip sprites for the gates.


|
private |
Set the score sprites and positions in the score descriptor. This function must only be called after the sprites have been loaded.
