Added FSM and Game State Manager
This commit is contained in:
57
src/game/GameStateManager.h
Normal file
57
src/game/GameStateManager.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
#include "StateMachine.h"
|
||||
|
||||
// Structure to hold event data passed into state StateMachine
|
||||
struct GameData : public EventData
|
||||
{
|
||||
char* menuId;
|
||||
bool win;
|
||||
};
|
||||
|
||||
// The Game State Machine Class
|
||||
class GameStateManager : public StateMachine
|
||||
{
|
||||
public:
|
||||
GameStateManager() : StateMachine(ST_MAX_STATES) {}
|
||||
|
||||
// external events taken by this state machine
|
||||
void AdvanceState();
|
||||
void GameOver();
|
||||
void PauseGame(GameData* gameData);
|
||||
private:
|
||||
//state machine state functions
|
||||
void ST_Init(EventData*);
|
||||
void ST_TitleScreen(EventData*);
|
||||
void ST_Instructions(GameData*);
|
||||
void ST_HiScoreList(GameData*);
|
||||
void ST_Credits(GameData*);
|
||||
void ST_CoreGame(EventData*);
|
||||
void ST_PauseScreen(EventData*);
|
||||
void ST_GameOver(GameData*);
|
||||
|
||||
//state map to define state function order
|
||||
BEGIN_STATE_MAP
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_Init)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_TitleScreen)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_Instructions)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_HiScoreList)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_Credits)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_CoreGame)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_PauseScreen)
|
||||
STATE_MAP_ENTRY(&GameStateManager::ST_GameOver)
|
||||
END_STATE_MAP
|
||||
|
||||
//state enumeration order must match order of state method entries on state map
|
||||
enum E_States {
|
||||
ST_INIT = 0,
|
||||
ST_TITLESCREEN,
|
||||
ST_INSTRUCTIONS,
|
||||
ST_HISCORELIST,
|
||||
ST_CREDITS,
|
||||
ST_COREGAME,
|
||||
ST_PAUSESCREEN,
|
||||
ST_GAMEOVER,
|
||||
ST_MAX_STATES
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user