December 2015
Beginner to intermediate
522 pages
11h 21m
English
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 ...
Read now
Unlock full access