nsnake
Classic snake game for the terminal
|
Abstract definition of a game state. More...
#include <GameState.hpp>
Public Types | |
enum | StateCode { QUIT, CONTINUE, MAIN_MENU, GAME_START, GAME_OVER } |
All possible transitions between states. More... | |
Public Member Functions | |
virtual void | load (int stack=0)=0 |
Where every state initializes it's resources. More... | |
virtual int | unload ()=0 |
Where every state destroys it's resources. More... | |
virtual StateCode | update ()=0 |
Called every frame, where states calculate everything that can change. More... | |
virtual void | draw ()=0 |
Called every frame, where states draw stuff on screen. | |
Abstract definition of a game state.
A game state is a certain well-defined way the game behaves.
Like the main menu (a state), for example. From there, the player can start the actual game (another state) and, show the pause menu (even another state).
Examples include the game over screen, high score screen, cutscenes, etc.
All the other game states inherit from this baby. Each one must implement at least four methods - load(), unload(), update() and draw().
Each state controls the game flow via return values of the update() method. If, for instance, the player dies during the game, it should return GAME_OVER or QUIT.
A state can also comunicate with the next one by returning a value from unload(). That value will be passed on the next state's load() and it should know what to do with it.
Definition at line 31 of file GameState.hpp.
enum GameState::StateCode |
All possible transitions between states.
They are used to change from one state to the other. The current state returns this at update() and the StateManager makes the appropriate changes.
Definition at line 39 of file GameState.hpp.
|
pure virtual |
Where every state initializes it's resources.
The stack is the previous state's returned value from unload(), allowing a state to communicate with the next one.
Implemented in GameStateGame, and GameStateMainMenu.
|
pure virtual |
Where every state destroys it's resources.
The returned value will be sent to the next state's load() so we can send a specific message to it.
Implemented in GameStateGame, and GameStateMainMenu.
|
pure virtual |
Called every frame, where states calculate everything that can change.
The returned value will be checked by the StateManager to see if we must change the current state - if so, which one should we go next.
Implemented in GameStateGame, and GameStateMainMenu.