diff --git a/Crawler/ClassInfo.h b/Crawler/ClassInfo.h index d3d1e5b0..3db94afc 100644 --- a/Crawler/ClassInfo.h +++ b/Crawler/ClassInfo.h @@ -20,7 +20,7 @@ struct ClassInfo{ class classutils{ public: static inline Class StringToClass(std::string className){ - std::vectorclassList=DATA["class_list"].GetValues(); + const std::vector&classList=DATA["class_list"].GetValues(); auto it=std::find(classList.begin(),classList.end(),className); int element=std::distance(classList.begin(),it); return Class(1<S(A::CLASS_SELECTION); data.game->ChangePlayerClass(classutils::StringToClass(selectedClass)); - GameState::ChangeState(States::GAME_RUN); + GameState::ChangeState(States::OVERWORLD_MAP); }); confirmButton->disabled=true; classSelectionWindow->AddComponent("Confirm",confirmButton); @@ -96,5 +96,5 @@ void Menu::InitializeClassSelectionWindow(){ for(IToggleable*item:toggleGroup){ item->SetToggleGroup(toggleGroup); - } + } } \ No newline at end of file diff --git a/Crawler/ConnectionPoint.h b/Crawler/ConnectionPoint.h new file mode 100644 index 00000000..d0cb1361 --- /dev/null +++ b/Crawler/ConnectionPoint.h @@ -0,0 +1,12 @@ +#include "olcPixelGameEngine.h" + +struct ConnectionPoint{ + vf2d pos; + 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){ + neighbors.fill(-1); + } +}; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 6b364b0b..1dbd3ba2 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -154,9 +154,8 @@ bool Crawler::OnUserUpdate(float fElapsedTime){ levelTime+=fElapsedTime; GameState::STATE->OnUserUpdate(this); RenderWorld(GetElapsedTime()); - RenderHud(); - RenderMenu(); GameState::STATE->Draw(this); + RenderMenu(); return true; } diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index a55ba0ad..96813e83 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -269,6 +269,7 @@ + @@ -350,6 +351,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index cc9c6f75..32321f59 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -210,6 +210,9 @@ Source Files + + Header Files + @@ -359,6 +362,9 @@ Header Files\Interface + + Source Files\Game States + diff --git a/Crawler/GameState.cpp b/Crawler/GameState.cpp index 2be5b39d..fbecba39 100644 --- a/Crawler/GameState.cpp +++ b/Crawler/GameState.cpp @@ -4,6 +4,7 @@ void GameState::Initialize(){ NEW_STATE(States::GAME_RUN,State_GameRun); + NEW_STATE(States::OVERWORLD_MAP,State_OverworldMap); NEW_STATE(States::MAIN_MENU,State_MainMenu); GameState::ChangeState(States::MAIN_MENU); diff --git a/Crawler/GameState.h b/Crawler/GameState.h index 1bb037d0..3bbde67a 100644 --- a/Crawler/GameState.h +++ b/Crawler/GameState.h @@ -1,12 +1,14 @@ #pragma once #include #include +#include "ConnectionPoint.h" class Crawler; namespace States{ enum State{ GAME_RUN, + OVERWORLD_MAP, MAIN_MENU, }; }; @@ -36,6 +38,14 @@ class State_GameRun:public GameState{ 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; diff --git a/Crawler/State_GameRun.cpp b/Crawler/State_GameRun.cpp index 6adc680c..1a16d1ad 100644 --- a/Crawler/State_GameRun.cpp +++ b/Crawler/State_GameRun.cpp @@ -31,5 +31,5 @@ void State_GameRun::OnUserUpdate(Crawler*game){ game->UpdateCamera(game->GetElapsedTime()); }; void State_GameRun::Draw(Crawler*game){ - + game->RenderHud(); }; \ No newline at end of file diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp new file mode 100644 index 00000000..205461e2 --- /dev/null +++ b/Crawler/State_OverworldMap.cpp @@ -0,0 +1,19 @@ +#include "GameState.h" +#include "Crawler.h" +#include "DEFINES.h" +#include "Menu.h" +#include "Item.h" + +INCLUDE_MONSTER_LIST + +std::vectorState_OverworldMap::connections; + +void State_OverworldMap::OnStateChange(GameState*prevState){ + Menu::CloseAllMenus(); +}; +void State_OverworldMap::OnUserUpdate(Crawler*game){ + +}; +void State_OverworldMap::Draw(Crawler*game){ + +}; \ No newline at end of file diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index e5b8d6d9..dfc36023 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -2,6 +2,7 @@ #include "olcPixelGameEngine.h" #include "olcUTIL_Geometry2D.h" #include +#include "GameState.h" using namespace olc; @@ -57,6 +58,20 @@ struct Map{ friend std::ostream& operator << (std::ostream& os, std::vector& rhs); }; +struct Property{ + std::string name; + std::string value; + int GetInteger(); + float GetFloat(); + double GetDouble(); + bool GetBool(); +}; + +struct StagePlate{ + XMLTag tag; + std::mapproperties; +}; + class TMXParser{ public: Map GetData(); @@ -69,13 +84,16 @@ class TMXParser{ int monsterPropertyTagCount=-1; XMLTag monsterTag; XMLTag spawnerLinkTag; + StagePlate*currentStagePlate; std::vectoraccumulatedMonsterTags; + std::mapstagePlates; bool infiniteMap=false; public: TMXParser(std::string file); }; typedef std::map>> ZoneData; +//#define TMX_PARSER_SETUP //Toggle for code-writing. #ifdef TMX_PARSER_SETUP #undef TMX_PARSER_SETUP @@ -114,6 +132,22 @@ typedef std::map>> ZoneData; return true; } } + int Property::GetInteger() { + return std::stoi(value); + } + float Property::GetFloat() { + return std::stof(value); + } + double Property::GetDouble() { + return std::stod(value); + } + bool Property::GetBool() { + if (value=="0") { + return false; + } else { + return true; + } + } MapTag::MapTag(){} MapTag::MapTag(int width,int height,int tilewidth,int tileheight) :width(width),height(height),tilewidth(tilewidth),tileheight(tileheight),MapSize({width,height}),TileSize({tilewidth,tileheight}){} @@ -221,24 +255,30 @@ typedef std::map>> ZoneData; }; XMLTag newTag=ReadNextTag(); + + if (newTag.tag=="object"&&newTag.data["type"]!="StagePlate") { + currentStagePlate=nullptr; + } - if (newTag.tag=="map") { + if (newTag.tag=="map"){ if(stoi(newTag.data["infinite"])==1){ infiniteMap=true; return; } parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"]),stoi(newTag.data["tilewidth"]),stoi(newTag.data["tileheight"])}; } else - if (newTag.tag=="tileset") { + if (newTag.tag=="tileset"){ parsedMapInfo.TilesetData.push_back(newTag); } else - if (newTag.tag=="layer") { + if (newTag.tag=="layer"){ LayerTag l = {newTag}; parsedMapInfo.LayerData.push_back(l); }else if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") { - parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag}; - prevSpawner=newTag.GetInteger("id"); + if(newTag.GetInteger("id")!=0){ + parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag}; + prevSpawner=newTag.GetInteger("id"); + } } else if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") { parsedMapInfo.MapData.optimized=true; @@ -250,10 +290,7 @@ typedef std::map>> ZoneData; parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; } else if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end() - &&newTag.data.find("x")!=newTag.data.end() - &&newTag.data.find("y")!=newTag.data.end() - &&newTag.data.find("width")!=newTag.data.end() - &&newTag.data.find("height")!=newTag.data.end()){ + &&(newTag.data["type"]=="LowerZone"||newTag.data["type"]=="UpperZone")){ //This is an object with a type that doesn't fit into other categories, we can add it to ZoneData. if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){ std::vector>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; @@ -280,7 +317,16 @@ typedef std::map>> ZoneData; monsterTag.data["spawnerLink"]=spawnerLinkTag.data["value"]; accumulatedMonsterTags.push_back(monsterTag); monsterPropertyTagCount=-1; - } else { + } else + if (newTag.tag=="object"&&newTag.data["type"]=="StagePlate") { + if(newTag.GetInteger("id")!=0){ + stagePlates[newTag.GetInteger("id")]={newTag}; + currentStagePlate=&stagePlates.at(newTag.GetInteger("id")); + } + } else + if(newTag.tag=="property"&¤tStagePlate!=nullptr){ + currentStagePlate->properties[newTag.data["name"]]={newTag.data["name"],newTag.data["value"]}; + }else{ if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n"; } if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n"; @@ -354,6 +400,30 @@ typedef std::map>> ZoneData; std::sort(parsedMapInfo.TilesetData.begin(),parsedMapInfo.TilesetData.end(),[](XMLTag&t1,XMLTag&t2){return t1.GetInteger("firstgid")idToIndexMap; //Since the original map data relies on IDs decided by Tiled and we are condensing all this data into a vector of connection points, each connection point is going to be in a different ID. + //therefore, we need to convert the Tiled IDs into whatever vector index we insert each connection into for State_OverworldMap::connections. + 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}; + int iterationCount=0; + for(auto key2:plate.properties){ + if(key2.first.starts_with("Connection ")){ + newConnection.neighbors[iterationCount]=key2.second.GetInteger(); + iterationCount++; + } + } + State_OverworldMap::connections.push_back(newConnection); + } + for(ConnectionPoint&connection:State_OverworldMap::connections){ + std::array; + for(int&val:connection.neighbors){ + if(idToIndexMap.count(val)){ + val=idToIndexMap.at(val); //Convert from given Tiled ID to indexed ID in State_OverworldMap::connections + } + } + } + if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"< + @@ -597,6 +598,8 @@ + + diff --git a/Crawler/olcPGEX_TransformedView.h b/Crawler/olcPGEX_TransformedView.h index c7396ae5..f94e76d8 100644 --- a/Crawler/olcPGEX_TransformedView.h +++ b/Crawler/olcPGEX_TransformedView.h @@ -82,8 +82,6 @@ Removed unused "range" facility in TileTransformView #include "olcPixelGameEngine.h" - - namespace olc { class TransformedView : public olc::PGEX diff --git a/x64/Release/Crawler.exe b/x64/Release/Crawler.exe index de214b23..36fd0819 100644 Binary files a/x64/Release/Crawler.exe and b/x64/Release/Crawler.exe differ