The 8-ball Pool End Game
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CGame Class Reference

The game class. More...

#include <Game.h>

Inheritance diagram for CGame:
Collaboration diagram for CGame:

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 LoadSprites ()
 Load sprites.
 
void LoadSounds ()
 Load sounds.
 
void CreateObjects ()
 Create game objects.
 
void BeginGame ()
 Begin playing the game.
 
void KeyboardHandler ()
 The keyboard handler.
 
void RenderFrame ()
 Render an animation frame.
 
void ProcessState ()
 Process game state.
 
void DrawFrameRateText ()
 Draw frame rate text to screen.
 

Private Attributes

bool m_bDrawFrameRate = false
 Draw the frame rate.
 
eGameState m_eGameState = eGameState::Loading
 Current game state.
 
float m_fGameStateTime = 0.0f
 Timer for game state changes.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static Sage::CParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static bool m_bShowCollisions = false
 Show ball positions at TOI.
 
static bool m_bStepMode = false
 Is in step mode.
 
static bool m_bStep = false
 Step flag.
 
static float m_fXMargin = 78.0f
 Horizontal margin.
 
static float m_fYMargin = 64.0f
 Vertical margin.
 
static Vector2 m_vMargin = Vector2(m_fXMargin, m_fYMargin)
 Margins.
 
static Vector2 m_vTopLPocket = Vector2(71, 478)
 Position of top left pocket.
 
static Vector2 m_vTopRPocket = Vector2(955, 478)
 Position of top right pocket.
 
static Vector2 m_vTopCPocket = Vector2(514, 478)
 Position of top center pocket.
 
static Vector2 m_vBotLPocket = Vector2(71, 53)
 Position of bottom left pocket.
 
static Vector2 m_vBotRPocket = Vector2(955, 53)
 Position of bottom right pocket.
 
static Vector2 m_vBotCPocket = Vector2(514, 48)
 Position of bottom center pocket.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~CGame()

CGame::~CGame ( )

Delete the renderer, the object manager, and the particle engine.

Member Function Documentation

◆ BeginGame()

void CGame::BeginGame ( )
private

Call this function to start a new game. This ought to be re-entrant so that we can restart a new game without having to shut down and restart the program, but it's moot here. All we really need to do is set the game state to the initial state, clear any old objects out of the object manager, and create some new ones.

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. This game has only two objects, the 8-ball and the cue-ball. This function creates them and sets the impulse vector to point from the cue-ball to the 8-ball.

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

◆ DrawFrameRateText()

void CGame::DrawFrameRateText ( )
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.

Here is the caller graph for this function:

◆ Initialize()

void CGame::Initialize ( )

Initialize the game as follows. Set the timer. Create the renderer, the particle engine, and the object manager. Load images and sounds from files.

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. The keys are identified using virtual-key codes.

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

◆ LoadSounds()

void CGame::LoadSounds ( )
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.

Here is the caller graph for this function:

◆ LoadSprites()

void CGame::LoadSprites ( )
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.

Here is the caller graph for this function:

◆ ProcessFrame()

void CGame::ProcessFrame ( )

This function will be called regularly to process and render a frame of animation, which involves the following. Handle keyboard input. Notify the sound player at the start of each frame so that it can prevent multiple copies of a sound from starting on the same frame.
Move the game objects. Render a frame of animation. Process any changes to the current game state.

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

◆ ProcessState()

void CGame::ProcessState ( )
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. Switch between playing, win, lose, and setup cue-ball states as appropriate.

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

Render the current animation frame. The renderer is notified of the start and end of the frame so that it can let Direct3D do its pipelining. Draw the background, the particles, the game objects, a win or lose text if appropriate, and the frame rate if required.

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