![]() |
The 8-ball Pool End Game
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 | DrawFrameRateText () |
Draw frame rate text to screen. More... | |
void | CreateObjects () |
Create game objects. More... | |
void | ProcessState () |
Process the game state. More... | |
Private Attributes | |
bool | m_bDrawFrameRate = false |
Draw the frame rate. | |
eGameState | m_eGameState = eGameState::Initial |
Current game state. | |
float | m_fGameStateTime = 0 |
Timer for game state changes. | |
Additional Inherited Members | |
![]() | |
static CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static LParticleEngine2D * | 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. | |
The game class encapsulates the game.
CGame::CGame | ( | ) |
The default constructor.
CGame::~CGame | ( | ) |
Delete the renderer, the object manager, and the particle engine.
|
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.
|
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.
|
private |
Draw the current frame rate to a hard-coded position in the window.
void CGame::Initialize | ( | ) |
Initialize the renderer, the particle engine, the step timer, and the object manager, load images and sounds, and begin the game.
|
private |
Poll the keyboard state and respond to the key presses that happened in the last frame. Responses to user keystrokes depend on the current game state.
|
private |
Initialize the audio player and load game sounds.
void CGame::ProcessFrame | ( | ) |
Process the current frame. This involves responding to keyboard input, moving the game objects and rendering them in their new positions and orientations. Also 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, notify the step timer of the start and end of the frame so that it can calculate frame time, and take any actions required by the current game state.
|
private |
Check whether the game state needs to be changed, and take the appropriate action if it does.
void CGame::Release | ( | ) |
Release all of the DirectX12 objects by deleting the renderer.
|
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.