Game State System Setup
This commit is contained in:
parent
d3f26d4bb0
commit
43661ee07f
@ -18,6 +18,7 @@
|
||||
#include "safemap.h"
|
||||
#include "Key.h"
|
||||
#include "Menu.h"
|
||||
#include "State_GameRun.h"
|
||||
|
||||
INCLUDE_EMITTER_LIST
|
||||
|
||||
@ -110,6 +111,11 @@ bool Crawler::OnUserCreate(){
|
||||
InitializeClasses();
|
||||
ChangePlayerClass(WARRIOR);
|
||||
//Warrior::ability4=Ranger::ability1; //Class ability swapping demonstration.
|
||||
|
||||
GameState::states[States::GAME_RUN]=new State_GameRun();
|
||||
|
||||
GameState::ChangeState(States::GAME_RUN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -132,9 +138,11 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
|
||||
monstersToBeSpawned.clear();
|
||||
UpdateBullets(fElapsedTime);
|
||||
UpdateCamera(fElapsedTime);
|
||||
GameState::STATE->OnUserUpdate(this);
|
||||
RenderWorld(fElapsedTime);
|
||||
RenderHud();
|
||||
RenderMenu();
|
||||
GameState::STATE->Draw(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,7 @@
|
||||
<ClInclude Include="DEFINES.h" />
|
||||
<ClInclude Include="Effect.h" />
|
||||
<ClInclude Include="Emitter.h" />
|
||||
<ClInclude Include="GameState.h" />
|
||||
<ClInclude Include="MenuIconButton.h" />
|
||||
<ClInclude Include="MenuLabel.h" />
|
||||
<ClInclude Include="MenuType.h" />
|
||||
@ -293,6 +294,7 @@
|
||||
<ClInclude Include="resource1.h" />
|
||||
<ClInclude Include="safemap.h" />
|
||||
<ClInclude Include="State.h" />
|
||||
<ClInclude Include="State_GameRun.h" />
|
||||
<ClInclude Include="Theme.h" />
|
||||
<ClInclude Include="TMXParser.h" />
|
||||
<ClInclude Include="TSXParser.h" />
|
||||
|
@ -46,6 +46,9 @@
|
||||
<Filter Include="Header Files\Interface">
|
||||
<UniqueIdentifier>{45ecf440-1472-4e9a-a4d9-e9eac538a2b0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Game States">
|
||||
<UniqueIdentifier>{da28101e-32b6-4e32-a19a-e0d2636d5eea}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="olcPixelGameEngine.h">
|
||||
@ -168,6 +171,12 @@
|
||||
<ClInclude Include="Attributable.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameState.h">
|
||||
<Filter>Header Files\Game States</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="State_GameRun.h">
|
||||
<Filter>Header Files\Game States</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
|
24
Crawler/GameState.h
Normal file
24
Crawler/GameState.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
class Crawler;
|
||||
|
||||
class State_GameRun;
|
||||
|
||||
namespace States{
|
||||
enum State{
|
||||
GAME_RUN
|
||||
};
|
||||
};
|
||||
|
||||
class GameState{
|
||||
public:
|
||||
inline static GameState*STATE=nullptr;
|
||||
inline static std::map<States::State,GameState*>states;
|
||||
virtual void OnStateChange(GameState*prevState)=0;
|
||||
virtual void OnUserUpdate(Crawler*game)=0;
|
||||
virtual void Draw(Crawler*game)=0;
|
||||
static inline void ChangeState(States::State newState){
|
||||
GameState*prevState=STATE;
|
||||
STATE=states[newState];
|
||||
STATE->OnStateChange(prevState);
|
||||
}
|
||||
};
|
15
Crawler/State_GameRun.h
Normal file
15
Crawler/State_GameRun.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameState.h"
|
||||
|
||||
class State_GameRun:public GameState{
|
||||
inline virtual void OnStateChange(GameState*prevState)override{
|
||||
|
||||
};
|
||||
inline virtual void OnUserUpdate(Crawler*game)override{
|
||||
|
||||
};
|
||||
inline virtual void Draw(Crawler*game)override{
|
||||
|
||||
};
|
||||
};
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 1761
|
||||
#define VERSION_BUILD 1765
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user