The state of the game
Remember when we coded the pause button back in Chapter 4, Control Freak? We had to add some code that told the game whether it was active or paused. In fact, we defined the following enums:
enum GameState { GS_Running, GS_Paused };
These enums
defined two game states: GS_Running
, and GS_Paused
. We then set the default game state to GS_Running
in the StartGame
function:
void StartGame()
{
inputManager = new Input(hWnd);
LoadTextures();
m_gameState = GS_Running;
srand(time(NULL));
pickupSpawnThreshold = 5.0f;
pickupSpawnTimer = 0.0f;
}
As long as the game state is set to GS_Running
, then the game continues to cycle through the game loop, processing updates, and rendering the scene. However, when you click the pause button, the game state is set to GS_Paused
. When the game is paused, we no longer update the game objects (that is, the robot, pickups, and enemies), but we do continue to render the scene and process the UI (user interface) so that buttons...