State management
Think about it. If we want our game to pause, then we have to set some kind of flag that tells the game that we want it to take a break. We could set up a Boolean:
bool m_isPaused;
We would set m_isPaused
to true
if the game is paused, and set it to false
if the game is running.
The problem with this approach is that there are a lot of special cases that we may run into in a real game. At any time the game might be:
Starting
Ending
Running
Paused
These are just some example of game states. A game state is a particular mode that requires special handling. As there can be so many states, we usually create a state manager to keep track of the state we are currently in.
Creating a state manager
The simplest version of a state manager begins with an enum that defines all of the game states. Open RoboRacer.cpp
and add the following code just under the include statements:
enum GameState { GS_Running, GS_Paused };
Then go to the variable declarations block and add the following line:
GameState...