Game State System Setup

pull/28/head
sigonasr2 1 year ago
parent d3f26d4bb0
commit 43661ee07f
  1. 8
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.vcxproj
  3. 9
      Crawler/Crawler.vcxproj.filters
  4. 24
      Crawler/GameState.h
  5. 15
      Crawler/State_GameRun.h
  6. 2
      Crawler/Version.h

@ -18,6 +18,7 @@
#include "safemap.h" #include "safemap.h"
#include "Key.h" #include "Key.h"
#include "Menu.h" #include "Menu.h"
#include "State_GameRun.h"
INCLUDE_EMITTER_LIST INCLUDE_EMITTER_LIST
@ -110,6 +111,11 @@ bool Crawler::OnUserCreate(){
InitializeClasses(); InitializeClasses();
ChangePlayerClass(WARRIOR); ChangePlayerClass(WARRIOR);
//Warrior::ability4=Ranger::ability1; //Class ability swapping demonstration. //Warrior::ability4=Ranger::ability1; //Class ability swapping demonstration.
GameState::states[States::GAME_RUN]=new State_GameRun();
GameState::ChangeState(States::GAME_RUN);
return true; return true;
} }
@ -132,9 +138,11 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
monstersToBeSpawned.clear(); monstersToBeSpawned.clear();
UpdateBullets(fElapsedTime); UpdateBullets(fElapsedTime);
UpdateCamera(fElapsedTime); UpdateCamera(fElapsedTime);
GameState::STATE->OnUserUpdate(this);
RenderWorld(fElapsedTime); RenderWorld(fElapsedTime);
RenderHud(); RenderHud();
RenderMenu(); RenderMenu();
GameState::STATE->Draw(this);
return true; return true;
} }

@ -271,6 +271,7 @@
<ClInclude Include="DEFINES.h" /> <ClInclude Include="DEFINES.h" />
<ClInclude Include="Effect.h" /> <ClInclude Include="Effect.h" />
<ClInclude Include="Emitter.h" /> <ClInclude Include="Emitter.h" />
<ClInclude Include="GameState.h" />
<ClInclude Include="MenuIconButton.h" /> <ClInclude Include="MenuIconButton.h" />
<ClInclude Include="MenuLabel.h" /> <ClInclude Include="MenuLabel.h" />
<ClInclude Include="MenuType.h" /> <ClInclude Include="MenuType.h" />
@ -293,6 +294,7 @@
<ClInclude Include="resource1.h" /> <ClInclude Include="resource1.h" />
<ClInclude Include="safemap.h" /> <ClInclude Include="safemap.h" />
<ClInclude Include="State.h" /> <ClInclude Include="State.h" />
<ClInclude Include="State_GameRun.h" />
<ClInclude Include="Theme.h" /> <ClInclude Include="Theme.h" />
<ClInclude Include="TMXParser.h" /> <ClInclude Include="TMXParser.h" />
<ClInclude Include="TSXParser.h" /> <ClInclude Include="TSXParser.h" />

@ -46,6 +46,9 @@
<Filter Include="Header Files\Interface"> <Filter Include="Header Files\Interface">
<UniqueIdentifier>{45ecf440-1472-4e9a-a4d9-e9eac538a2b0}</UniqueIdentifier> <UniqueIdentifier>{45ecf440-1472-4e9a-a4d9-e9eac538a2b0}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Header Files\Game States">
<UniqueIdentifier>{da28101e-32b6-4e32-a19a-e0d2636d5eea}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="olcPixelGameEngine.h"> <ClInclude Include="olcPixelGameEngine.h">
@ -168,6 +171,12 @@
<ClInclude Include="Attributable.h"> <ClInclude Include="Attributable.h">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </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>
<ItemGroup> <ItemGroup>
<ClCompile Include="Player.cpp"> <ClCompile Include="Player.cpp">

@ -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);
}
};

@ -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_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 1761 #define VERSION_BUILD 1765
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save