From 4f65d2240a3ee127c9a655b939d3a4fcf292f3b6 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 4 Nov 2023 22:19:25 -0500 Subject: [PATCH] Navigation between unlocked stages is now possible. --- Crawler/ConnectionPoint.h | 5 ++-- Crawler/Crawler.cpp | 22 ++++++++++++--- Crawler/Crawler.h | 1 + Crawler/Crawler.vcxproj | 2 ++ Crawler/Crawler.vcxproj.filters | 6 +++++ Crawler/State_OverworldMap.cpp | 48 ++++++++++++++++++++++++++++++++- Crawler/State_OverworldMap.h | 5 ++++ Crawler/TMXParser.h | 17 +++++++++++- Crawler/Unlock.cpp | 21 +++++++++++++++ Crawler/Unlock.h | 14 ++++++++++ Crawler/Version.h | 4 +-- 11 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 Crawler/Unlock.cpp create mode 100644 Crawler/Unlock.h diff --git a/Crawler/ConnectionPoint.h b/Crawler/ConnectionPoint.h index 7bb9594a..18526869 100644 --- a/Crawler/ConnectionPoint.h +++ b/Crawler/ConnectionPoint.h @@ -1,3 +1,4 @@ +#pragma once #include "olcUTIL_Geometry2D.h" struct ConnectionPoint{ @@ -5,8 +6,8 @@ struct ConnectionPoint{ std::string name; std::string map; std::string unlockCondition; - std::arrayneighbors; //Indices into the connectionPoint array. - ConnectionPoint(geom2d::rectrect,std::string name,std::string map,std::string unlockCondition) + std::arrayneighbors; //Indices into the connectionPoint array. + inline 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 94e7cf8a..2e1cea6b 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -21,6 +21,8 @@ #include "GameState.h" #include "Item.h" #include "Toggleable.h" +#include "Unlock.h" +#include "State_OverworldMap.h" INCLUDE_EMITTER_LIST @@ -144,6 +146,8 @@ bool Crawler::OnUserCreate(){ GameState::Initialize(); + Unlock::Initialize(); + ValidateGameStatus(); //Checks to make sure everything has been initialized properly. return true; @@ -156,6 +160,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){ RenderWorld(GetElapsedTime()); GameState::STATE->Draw(this); RenderMenu(); + RenderVersionInfo(); return true; } @@ -1054,8 +1059,6 @@ void Crawler::RenderHud(){ DrawShadowStringPropDecal(vf2d{float(ScreenWidth()/2),float(ScreenHeight()/4)-24}-GetTextSizeProp(displayText)/2,displayText,BLUE,VERY_DARK_BLUE); } DisplayBossEncounterInfo(); - std::string versionStr("v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH) + "." + std::to_string(VERSION_BUILD)); - DrawShadowStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4,versionStr,WHITE,BLACK,{0.4,0.4},0.4); if("debug_player_info"_I){ DrawShadowStringDecal({0,128},player->GetPos().str()); DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult())); @@ -1543,7 +1546,7 @@ datafiledoubledata Crawler::GetDoubleList(std::string key){ int main() { Crawler demo; - if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4, false)) + if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4)) demo.Start(); return 0; @@ -1828,4 +1831,17 @@ void Crawler::ValidateGameStatus(){ std::cout<<"Error TOGGLE!!! Please turn on debug_toggleable_items in configuration.txt and re-run the program to see which toggleable item did not properly get a toggleable group set."< + @@ -360,6 +361,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 620fbe33..4df69dea 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -225,6 +225,9 @@ Header Files\State + + Header Files + @@ -377,6 +380,9 @@ Source Files\Game States + + Source Files + diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp index 7056ff7f..8b6c37f8 100644 --- a/Crawler/State_OverworldMap.cpp +++ b/Crawler/State_OverworldMap.cpp @@ -3,6 +3,9 @@ #include "Crawler.h" #include "DEFINES.h" #include "Menu.h" +#include "Unlock.h" +#include "ConnectionPoint.h" +#include "utils.h" INCLUDE_MONSTER_LIST INCLUDE_game @@ -14,7 +17,8 @@ State_OverworldMap::State_OverworldMap(){ } void State_OverworldMap::OnStateChange(GameState*prevState){ Menu::CloseAllMenus(); - game->GetPlayer()->SetPos(currentConnectionPoint->rect.pos); + game->GetPlayer()->SetPos(currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16}); + playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16}; game->GetPlayer()->UpdateWalkingAnimation(DOWN); game->GetPlayer()->SetState(State::FORCE_WALK); game->GetPlayer()->SetSizeMult(1); @@ -23,6 +27,40 @@ void State_OverworldMap::OnUserUpdate(Crawler*game){ game->camera.SetTarget(currentConnectionPoint->rect.middle()); game->UpdateCamera(game->GetElapsedTime()); game->GetPlayer()->Update(game->GetElapsedTime()); + + if(game->GetPlayer()->GetPos()!=playerTargetPos){ + if(geom2d::line(game->GetPlayer()->GetPos(),playerTargetPos).length()<2){ + game->GetPlayer()->SetPos(playerTargetPos); + }else{ + game->GetPlayer()->SetPos(game->GetPlayer()->GetPos()+util::pointTo(game->GetPlayer()->GetPos(),playerTargetPos)*playerMoveSpd*game->GetElapsedTime()); + } + } + + for(ConnectionPoint&cp:connections){ + if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){ + for(int neighborInd:currentConnectionPoint->neighbors){ + if(neighborInd==-1)continue; + ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd); + if(Unlock::IsUnlocked(neighbor.name)&&&cp==&neighbor){ + currentConnectionPoint=&neighbor; + playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16}; + float angleTo=util::angleTo(game->GetPlayer()->GetPos(),playerTargetPos); + if(angleTo>=-3*PI/4&&angleTo<-PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(UP); + }else + if(angleTo=-PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(RIGHT); + }else + if(angleTo>=PI/4&&angleTo<3*PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(DOWN); + }else{ + game->GetPlayer()->UpdateWalkingAnimation(LEFT); + } + break; + } + } + } + } }; void State_OverworldMap::Draw(Crawler*game){ currentTime+=game->GetElapsedTime(); @@ -72,4 +110,12 @@ void State_OverworldMap::SetStageMarker(std::string connectionName){ } std::cout<<"WARNING! Could not find a connection point with name "<currentConnectionPoint; } \ No newline at end of file diff --git a/Crawler/State_OverworldMap.h b/Crawler/State_OverworldMap.h index cee0b4e4..e0a6899e 100644 --- a/Crawler/State_OverworldMap.h +++ b/Crawler/State_OverworldMap.h @@ -3,12 +3,17 @@ #include "ConnectionPoint.h" class State_OverworldMap:public GameState{ + friend class Crawler; ConnectionPoint*currentConnectionPoint; float currentTime; + vf2d playerTargetPos; + const float playerMoveSpd=48.0; public: State_OverworldMap(); static std::vectorconnections; + static ConnectionPoint&GetCurrentConnectionPoint(); void SetStageMarker(std::string connectionName); + ConnectionPoint&ConnectionPointFromIndex(int ind); virtual void OnStateChange(GameState*prevState)override; virtual void OnUserUpdate(Crawler*game)override; virtual void Draw(Crawler*game)override; diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index 35019bde..7d46fdfc 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -416,13 +416,28 @@ typedef std::map>> ZoneData; 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 } } } + int counter=0; + for(ConnectionPoint&connection:State_OverworldMap::connections){ + for(int val:connection.neighbors){ + if(val!=-1){ + ConnectionPoint&neighbor=State_OverworldMap::connections.at(val); + //Find a blank slot that is available. + for(int i=0;iUnlock::unlocks; + +void Unlock::Initialize(){ + UnlockArea("Stage I-I"); + UnlockArea("Shop I"); + UnlockArea("Blacksmith I"); + UnlockArea("Stage I-II"); +} + +void Unlock::UnlockArea(std::string unlock){ + unlocks.insert(unlock); +} +bool Unlock::IsUnlocked(std::string unlock){ + return unlocks.count(unlock); +} + +bool Unlock::IsUnlocked(ConnectionPoint&cp){ + return unlocks.count(cp.name); +} \ No newline at end of file diff --git a/Crawler/Unlock.h b/Crawler/Unlock.h new file mode 100644 index 00000000..87cc1386 --- /dev/null +++ b/Crawler/Unlock.h @@ -0,0 +1,14 @@ +#pragma once +#include +#include +#include "ConnectionPoint.h" + +class Unlock{ + friend class Crawler; + static std::setunlocks; + static void Initialize(); +public: + static void UnlockArea(std::string unlock); + static bool IsUnlocked(std::string unlock); + static bool IsUnlocked(ConnectionPoint&cp); +}; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index 79ac2171..346266b8 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -1,8 +1,8 @@ #pragma once #define VERSION_MAJOR 0 #define VERSION_MINOR 2 -#define VERSION_PATCH 0 -#define VERSION_BUILD 2485 +#define VERSION_PATCH 1 +#define VERSION_BUILD 2513 #define stringify(a) stringify_(a) #define stringify_(a) #a