Main Menu and Game Play state switching.
This commit is contained in:
parent
43661ee07f
commit
773f72a45c
@ -18,7 +18,7 @@
|
||||
#include "safemap.h"
|
||||
#include "Key.h"
|
||||
#include "Menu.h"
|
||||
#include "State_GameRun.h"
|
||||
#include "GameState.h"
|
||||
|
||||
INCLUDE_EMITTER_LIST
|
||||
|
||||
@ -112,9 +112,7 @@ bool Crawler::OnUserCreate(){
|
||||
ChangePlayerClass(WARRIOR);
|
||||
//Warrior::ability4=Ranger::ability1; //Class ability swapping demonstration.
|
||||
|
||||
GameState::states[States::GAME_RUN]=new State_GameRun();
|
||||
|
||||
GameState::ChangeState(States::GAME_RUN);
|
||||
GameState::Initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -122,26 +120,10 @@ bool Crawler::OnUserCreate(){
|
||||
bool Crawler::OnUserUpdate(float fElapsedTime){
|
||||
fElapsedTime=std::clamp(fElapsedTime,0.f,1/30.f); //HACK fix. We can't have a negative time. Although using a more precise system clock should make this never occur. Also make sure if the game is too slow we advance by only 1/30th of a second.
|
||||
levelTime+=fElapsedTime;
|
||||
bossDisplayTimer=std::max(0.f,bossDisplayTimer-fElapsedTime);
|
||||
if(encounterStarted&&totalBossEncounterMobs>0){
|
||||
encounterDuration+=fElapsedTime;
|
||||
}
|
||||
HandleUserInput(fElapsedTime);
|
||||
UpdateEffects(fElapsedTime);
|
||||
player->Update(fElapsedTime);
|
||||
for(Monster&m:MONSTER_LIST){
|
||||
m.Update(fElapsedTime);
|
||||
}
|
||||
for(Monster&m:monstersToBeSpawned){
|
||||
MONSTER_LIST.push_back(m);
|
||||
}
|
||||
monstersToBeSpawned.clear();
|
||||
UpdateBullets(fElapsedTime);
|
||||
UpdateCamera(fElapsedTime);
|
||||
GameState::STATE->OnUserUpdate(this);
|
||||
RenderWorld(fElapsedTime);
|
||||
RenderHud();
|
||||
RenderMenu();
|
||||
game->RenderWorld(game->GetElapsedTime());
|
||||
game->RenderHud();
|
||||
game->RenderMenu();
|
||||
GameState::STATE->Draw(this);
|
||||
return true;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
class Crawler : public olc::PixelGameEngine
|
||||
{
|
||||
friend class State_GameRun;
|
||||
friend class sig::Animation;
|
||||
Camera2D camera;
|
||||
std::unique_ptr<Player>player;
|
||||
@ -51,13 +52,14 @@ private:
|
||||
float reflectionUpdateTimer=0;
|
||||
float reflectionStepTime=0;
|
||||
std::set<vi2d>visibleTiles;
|
||||
std::vector<Monster>monstersToBeSpawned;
|
||||
float bossDisplayTimer=0;
|
||||
std::string bossName;
|
||||
int totalDamageDealt=0;
|
||||
float encounterDuration=0;
|
||||
bool encounterStarted=false;
|
||||
int totalBossEncounterMobs=0;
|
||||
|
||||
std::vector<Monster>monstersToBeSpawned;
|
||||
public:
|
||||
Crawler();
|
||||
bool OnUserCreate() override;
|
||||
|
@ -294,7 +294,6 @@
|
||||
<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" />
|
||||
@ -314,6 +313,7 @@
|
||||
<ClCompile Include="EnergyBolt.cpp" />
|
||||
<ClCompile Include="FallingDebris.h" />
|
||||
<ClCompile Include="FireBolt.cpp" />
|
||||
<ClCompile Include="GameState.cpp" />
|
||||
<ClCompile Include="Key.cpp" />
|
||||
<ClCompile Include="LightningBolt.cpp" />
|
||||
<ClCompile Include="LightningBoltEmitter.cpp" />
|
||||
@ -333,6 +333,8 @@
|
||||
<ClCompile Include="RUN_STRATEGY.cpp" />
|
||||
<ClCompile Include="ShootAfar.cpp" />
|
||||
<ClCompile Include="SlimeKing.cpp" />
|
||||
<ClCompile Include="State_GameRun.cpp" />
|
||||
<ClCompile Include="State_MainMenu.cpp" />
|
||||
<ClCompile Include="TestMenu.cpp" />
|
||||
<ClCompile Include="TestSubMenu.cpp" />
|
||||
<ClCompile Include="Thief.cpp" />
|
||||
|
@ -49,6 +49,9 @@
|
||||
<Filter Include="Header Files\Game States">
|
||||
<UniqueIdentifier>{da28101e-32b6-4e32-a19a-e0d2636d5eea}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Game States">
|
||||
<UniqueIdentifier>{f36af2ba-e884-4e50-b7bd-7e6aa9a8528c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="olcPixelGameEngine.h">
|
||||
@ -174,9 +177,6 @@
|
||||
<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">
|
||||
@ -299,6 +299,15 @@
|
||||
<ClCompile Include="TestSubMenu.cpp">
|
||||
<Filter>Source Files\Interface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="State_GameRun.cpp">
|
||||
<Filter>Source Files\Game States</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameState.cpp">
|
||||
<Filter>Source Files\Game States</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="State_MainMenu.cpp">
|
||||
<Filter>Source Files\Game States</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
10
Crawler/GameState.cpp
Normal file
10
Crawler/GameState.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "GameState.h"
|
||||
|
||||
#define NEW_STATE(state,class) GameState::states[state]=new class();
|
||||
|
||||
void GameState::Initialize(){
|
||||
NEW_STATE(States::GAME_RUN,State_GameRun);
|
||||
NEW_STATE(States::MAIN_MENU,State_MainMenu);
|
||||
|
||||
GameState::ChangeState(States::GAME_RUN);
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
class Crawler;
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
class State_GameRun;
|
||||
class Crawler;
|
||||
|
||||
namespace States{
|
||||
enum State{
|
||||
GAME_RUN
|
||||
GAME_RUN,
|
||||
MAIN_MENU,
|
||||
};
|
||||
};
|
||||
|
||||
@ -13,12 +15,29 @@ class GameState{
|
||||
public:
|
||||
inline static GameState*STATE=nullptr;
|
||||
inline static std::map<States::State,GameState*>states;
|
||||
static void Initialize();
|
||||
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];
|
||||
if(!states.count(newState)){
|
||||
std::cout<<"WARNING! State not defined for state "<<newState<<"!"<<std::endl;
|
||||
throw;
|
||||
}
|
||||
STATE=states.at(newState);
|
||||
STATE->OnStateChange(prevState);
|
||||
}
|
||||
};
|
||||
|
||||
class State_GameRun:public GameState{
|
||||
virtual void OnStateChange(GameState*prevState)override;
|
||||
virtual void OnUserUpdate(Crawler*game)override;
|
||||
virtual void Draw(Crawler*game)override;
|
||||
};
|
||||
|
||||
class State_MainMenu:public GameState{
|
||||
virtual void OnStateChange(GameState*prevState)override;
|
||||
virtual void OnUserUpdate(Crawler*game)override;
|
||||
virtual void Draw(Crawler*game)override;
|
||||
};
|
@ -27,6 +27,7 @@ struct Player{
|
||||
friend class Trapper;
|
||||
friend class Wizard;
|
||||
friend class Witch;
|
||||
friend class State_GameRun;
|
||||
private:
|
||||
int hp="Player.BaseHealth"_I,maxhp=hp;
|
||||
int mana="Player.BaseMana"_I,maxmana=mana;
|
||||
|
36
Crawler/State_GameRun.cpp
Normal file
36
Crawler/State_GameRun.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "GameState.h"
|
||||
#include "Crawler.h"
|
||||
#include "DEFINES.h"
|
||||
#include "Menu.h"
|
||||
|
||||
INCLUDE_MONSTER_LIST
|
||||
|
||||
void State_GameRun::OnStateChange(GameState*prevState){
|
||||
Menu::stack.clear();
|
||||
};
|
||||
void State_GameRun::OnUserUpdate(Crawler*game){
|
||||
game->bossDisplayTimer=std::max(0.f,game->bossDisplayTimer-game->GetElapsedTime());
|
||||
if(game->encounterStarted&&game->totalBossEncounterMobs>0){
|
||||
game->encounterDuration+=game->GetElapsedTime();
|
||||
}
|
||||
game->HandleUserInput(game->GetElapsedTime());
|
||||
|
||||
if(game->GetKey(T).bPressed){
|
||||
GameState::ChangeState(States::MAIN_MENU);
|
||||
}
|
||||
|
||||
game->UpdateEffects(game->GetElapsedTime());
|
||||
game->GetPlayer()->Update(game->GetElapsedTime());
|
||||
for(Monster&m:MONSTER_LIST){
|
||||
m.Update(game->GetElapsedTime());
|
||||
}
|
||||
for(Monster&m:game->monstersToBeSpawned){
|
||||
MONSTER_LIST.push_back(m);
|
||||
}
|
||||
game->monstersToBeSpawned.clear();
|
||||
|
||||
game->UpdateBullets(game->GetElapsedTime());
|
||||
game->UpdateCamera(game->GetElapsedTime());
|
||||
};
|
||||
void State_GameRun::Draw(Crawler*game){
|
||||
};
|
@ -1,15 +0,0 @@
|
||||
#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{
|
||||
|
||||
};
|
||||
};
|
16
Crawler/State_MainMenu.cpp
Normal file
16
Crawler/State_MainMenu.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "GameState.h"
|
||||
#include "Crawler.h"
|
||||
#include "Menu.h"
|
||||
|
||||
void State_MainMenu::OnStateChange(GameState*prevState){
|
||||
Menu::OpenMenu(MenuType::TEST);
|
||||
};
|
||||
void State_MainMenu::OnUserUpdate(Crawler*game){
|
||||
|
||||
if(game->GetKey(T).bPressed){
|
||||
GameState::ChangeState(States::GAME_RUN);
|
||||
}
|
||||
};
|
||||
void State_MainMenu::Draw(Crawler*game){
|
||||
game->DrawShadowStringDecal({0,0},"This will eventually be\nMain Menu stuff",BLACK,WHITE,{1,1},1);
|
||||
};
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 1765
|
||||
#define VERSION_BUILD 1777
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user