From c065e9f6fb1ad430b2b50623fef7685e5844a79a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 29 Oct 2023 17:00:54 -0500 Subject: [PATCH] Fix State_OverworldMap dependency in TMXParser.h --- Crawler/ConnectionPoint.h | 9 +++++---- Crawler/Crawler.cpp | 2 -- Crawler/Crawler.h | 2 +- Crawler/Crawler.vcxproj | 3 +++ Crawler/Crawler.vcxproj.filters | 12 ++++++++++++ Crawler/GameState.cpp | 3 +++ Crawler/GameState.h | 21 --------------------- Crawler/MenuAnimatedIconButton.h | 1 - Crawler/Player.h | 14 +++++++------- Crawler/State_GameRun.cpp | 3 +-- Crawler/State_GameRun.h | 8 ++++++++ Crawler/State_MainMenu.cpp | 2 +- Crawler/State_MainMenu.h | 7 +++++++ Crawler/State_OverworldMap.cpp | 24 ++++++++++++++++++++---- Crawler/State_OverworldMap.h | 14 ++++++++++++++ Crawler/TMXParser.h | 4 ++-- Crawler/Version.h | 2 +- Crawler/assets/Campaigns/World_Map.tmx | 18 +++++++++--------- 18 files changed, 94 insertions(+), 55 deletions(-) create mode 100644 Crawler/State_GameRun.h create mode 100644 Crawler/State_MainMenu.h create mode 100644 Crawler/State_OverworldMap.h diff --git a/Crawler/ConnectionPoint.h b/Crawler/ConnectionPoint.h index d0cb1361..7bb9594a 100644 --- a/Crawler/ConnectionPoint.h +++ b/Crawler/ConnectionPoint.h @@ -1,12 +1,13 @@ -#include "olcPixelGameEngine.h" +#include "olcUTIL_Geometry2D.h" struct ConnectionPoint{ - vf2d pos; + geom2d::rectrect; + std::string name; std::string map; std::string unlockCondition; std::arrayneighbors; //Indices into the connectionPoint array. - ConnectionPoint(vf2d pos,std::string map,std::string unlockCondition) - :pos(pos),map(map),unlockCondition(unlockCondition){ + ConnectionPoint(geom2d::rectrect,std::string name,std::string map,std::string unlockCondition) + :rect(rect),name(name),map(map),unlockCondition(unlockCondition){ neighbors.fill(-1); } }; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 1dbd3ba2..94e7cf8a 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -390,8 +390,6 @@ void Crawler::UpdateCamera(float fElapsedTime){ worldShakeVel.y*=-1; } worldShake=player->GetPos()+worldShakeVel*fElapsedTime; - } else { - camera.SetTarget(player->GetPos()); } worldShakeTime=std::max(0.f,worldShakeTime-fElapsedTime); camera.Update(fElapsedTime); diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 945ce4cd..672aab77 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -17,7 +17,6 @@ class Crawler : public olc::PixelGameEngine { friend class State_GameRun; friend class sig::Animation; - Camera2D camera; std::unique_ptrplayer; public: Pathfinding pathfinder; @@ -28,6 +27,7 @@ public: static InputGroup KEY_DOWN; static float SIZE_CHANGE_SPEED; float levelTime; + Camera2D camera; private: std::vector>foregroundEffects,backgroundEffects,foregroundEffectsToBeInserted,backgroundEffectsToBeInserted; std::vectortilePreparationList,tileForegroundList; diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 96813e83..be892916 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -303,6 +303,9 @@ + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 32321f59..620fbe33 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -58,6 +58,9 @@ {bea40439-f3a2-42f8-be1a-c0a815007075} + + {948a122a-3110-45f6-82d5-9b6bc499e3d2} + @@ -213,6 +216,15 @@ Header Files + + Header Files\State + + + Header Files\State + + + Header Files\State + diff --git a/Crawler/GameState.cpp b/Crawler/GameState.cpp index fbecba39..5b0be112 100644 --- a/Crawler/GameState.cpp +++ b/Crawler/GameState.cpp @@ -1,4 +1,7 @@ #include "GameState.h" +#include "State_GameRun.h" +#include "State_OverworldMap.h" +#include "State_MainMenu.h" #define NEW_STATE(state,class) GameState::states[state]=new class(); diff --git a/Crawler/GameState.h b/Crawler/GameState.h index 3bbde67a..9a71578b 100644 --- a/Crawler/GameState.h +++ b/Crawler/GameState.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include "ConnectionPoint.h" class Crawler; @@ -30,24 +29,4 @@ public: 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_OverworldMap:public GameState{ -public: - static std::vectorconnections; - 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; }; \ No newline at end of file diff --git a/Crawler/MenuAnimatedIconButton.h b/Crawler/MenuAnimatedIconButton.h index 05097047..f108511f 100644 --- a/Crawler/MenuAnimatedIconButton.h +++ b/Crawler/MenuAnimatedIconButton.h @@ -1,7 +1,6 @@ #pragma once #include "MenuIconButton.h" #include "DEFINES.h" -#include "Crawler.h" INCLUDE_game INCLUDE_ANIMATION_DATA diff --git a/Crawler/Player.h b/Crawler/Player.h index 72f98f35..0db0eaa5 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -69,13 +69,6 @@ protected: void SetFacingDirection(Key direction); void SetLastReleasedMovementKey(Key k); void Spin(float duration,float spinSpd); - //Returns true if the move was valid and successful. - bool SetX(float x); - //Returns true if the move was valid and successful. - bool SetY(float y); - void SetZ(float z); - //Returns true if the move was valid and successful. - bool SetPos(vf2d pos); float friction="Player.Friction"_F; float attack_cooldown_timer=0; float teleportAnimationTimer=0; @@ -140,6 +133,13 @@ public: void SetIframes(float duration); void RestoreMana(int amt); void ConsumeMana(int amt); + //Returns true if the move was valid and successful. + bool SetX(float x); + //Returns true if the move was valid and successful. + bool SetY(float y); + void SetZ(float z); + //Returns true if the move was valid and successful. + bool SetPos(vf2d pos); void AddBuff(BuffType type,float duration,float intensity); std::vectorGetBuffs(BuffType buff); diff --git a/Crawler/State_GameRun.cpp b/Crawler/State_GameRun.cpp index 1a16d1ad..ffe55f46 100644 --- a/Crawler/State_GameRun.cpp +++ b/Crawler/State_GameRun.cpp @@ -1,8 +1,7 @@ -#include "GameState.h" +#include "State_GameRun.h" #include "Crawler.h" #include "DEFINES.h" #include "Menu.h" -#include "Item.h" INCLUDE_MONSTER_LIST diff --git a/Crawler/State_GameRun.h b/Crawler/State_GameRun.h new file mode 100644 index 00000000..fc2fa0ef --- /dev/null +++ b/Crawler/State_GameRun.h @@ -0,0 +1,8 @@ +#pragma once +#include "GameState.h" + +class State_GameRun:public GameState{ + virtual void OnStateChange(GameState*prevState)override; + virtual void OnUserUpdate(Crawler*game)override; + virtual void Draw(Crawler*game)override; +}; \ No newline at end of file diff --git a/Crawler/State_MainMenu.cpp b/Crawler/State_MainMenu.cpp index cd969223..a6d787d4 100644 --- a/Crawler/State_MainMenu.cpp +++ b/Crawler/State_MainMenu.cpp @@ -1,4 +1,4 @@ -#include "GameState.h" +#include "State_MainMenu.h" #include "Crawler.h" #include "Menu.h" diff --git a/Crawler/State_MainMenu.h b/Crawler/State_MainMenu.h new file mode 100644 index 00000000..82e29176 --- /dev/null +++ b/Crawler/State_MainMenu.h @@ -0,0 +1,7 @@ +#include "GameState.h" + +class State_MainMenu:public GameState{ + virtual void OnStateChange(GameState*prevState)override; + virtual void OnUserUpdate(Crawler*game)override; + virtual void Draw(Crawler*game)override; +}; \ No newline at end of file diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp index 205461e2..faee8551 100644 --- a/Crawler/State_OverworldMap.cpp +++ b/Crawler/State_OverworldMap.cpp @@ -1,19 +1,35 @@ -#include "GameState.h" +#pragma once +#include "State_OverworldMap.h" #include "Crawler.h" #include "DEFINES.h" #include "Menu.h" -#include "Item.h" INCLUDE_MONSTER_LIST +INCLUDE_game std::vectorState_OverworldMap::connections; +State_OverworldMap::State_OverworldMap(){ + SetStageMarker("Stage I-I"); //Eventually we will load the game from a file and this will not be necessary. We just set it to this for now. + game->GetPlayer()->SetPos(currentConnectionPoint->rect.pos); +} void State_OverworldMap::OnStateChange(GameState*prevState){ Menu::CloseAllMenus(); }; void State_OverworldMap::OnUserUpdate(Crawler*game){ - + game->camera.SetTarget(currentConnectionPoint->rect.middle()); + game->UpdateCamera(game->GetElapsedTime()); }; void State_OverworldMap::Draw(Crawler*game){ -}; \ No newline at end of file +}; +void State_OverworldMap::SetStageMarker(std::string connectionName){ + for(ConnectionPoint&connection:connections){ + if(connection.name==connectionName){ + currentConnectionPoint=&connection; + return; + } + } + std::cout<<"WARNING! Could not find a connection point with name "<connections; + void SetStageMarker(std::string connectionName); + virtual void OnStateChange(GameState*prevState)override; + virtual void OnUserUpdate(Crawler*game)override; + virtual void Draw(Crawler*game)override; +}; \ No newline at end of file diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index dfc36023..35019bde 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -2,7 +2,6 @@ #include "olcPixelGameEngine.h" #include "olcUTIL_Geometry2D.h" #include -#include "GameState.h" using namespace olc; @@ -97,6 +96,7 @@ typedef std::map>> ZoneData; #ifdef TMX_PARSER_SETUP #undef TMX_PARSER_SETUP + #include "State_OverworldMap.h" extern bool _DEBUG_MAP_LOAD_INFO; const std::string XMLTag::FormatTagData(std::maptiles){ std::string displayStr=""; @@ -405,7 +405,7 @@ typedef std::map>> ZoneData; for(auto key:stagePlates){ StagePlate&plate=key.second; idToIndexMap[plate.tag.GetInteger("id")]=State_OverworldMap::connections.size(); - ConnectionPoint newConnection={{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},plate.properties["Map"].value,plate.properties["Unlock Condition"].value}; + ConnectionPoint newConnection={{{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},{plate.tag.GetFloat("width"),plate.tag.GetFloat("height")}},plate.tag.data["name"],plate.properties["Map"].value,plate.properties["Unlock Condition"].value}; int iterationCount=0; for(auto key2:plate.properties){ if(key2.first.starts_with("Connection ")){ diff --git a/Crawler/Version.h b/Crawler/Version.h index e9f8b69b..bee5e765 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 2428 +#define VERSION_BUILD 2450 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/Campaigns/World_Map.tmx b/Crawler/assets/Campaigns/World_Map.tmx index 6a9c0af3..ad59ca96 100644 --- a/Crawler/assets/Campaigns/World_Map.tmx +++ b/Crawler/assets/Campaigns/World_Map.tmx @@ -1,5 +1,5 @@ - + @@ -554,27 +554,27 @@ - + - + - + - + @@ -583,20 +583,20 @@ - + - + - + @@ -604,7 +604,7 @@ - +