The most simplistic approach
Let's begin by illustrating the most common approach newcomers take in order to solve this problem. It starts by enumerating all the possible states a game could have:
enum class StateType{ Intro = 1, MainMenu, Game, Paused, GameOver, Credits };
Good start. Now let's put it to work by simply using a switch
statement:
void Game::Update(){ switch(m_state){ case(StateType::Intro): UpdateIntro(); break; case(StateType::Game): UpdateGame(); break; case(StateType::MainMenu): UpdateMenu(); break; ... } }
The same goes for drawing it on screen:
void Game::Render(){ switch(m_state){ case(StateType::Intro): DrawIntro(); break; case(StateType::Game): DrawGame(); break; case(StateType::MainMenu): DrawMenu(); break; ... } }
While this approach is okay for really small games, scalability here is completely out of the question. First of all, the switch statements...