From bc07f58c9a37afa6fddca4cb8ae909aefdf1e6b3 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 12 Nov 2023 21:02:23 -0600 Subject: [PATCH] Fix centering of camera for overworld map. --- Crawler/ConnectionPoint.cpp | 11 +++++++++++ Crawler/ConnectionPoint.h | 1 + Crawler/Crawler.cpp | 8 +++++--- Crawler/Crawler.vcxproj | 2 +- Crawler/Crawler.vcxproj.filters | 12 ++++++------ Crawler/OverworldDisplayWindow.cpp | 0 Crawler/State_OverworldMap.cpp | 10 +++++----- Crawler/State_OverworldMap.h | 4 ++-- Crawler/Version.h | 2 +- 9 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 Crawler/ConnectionPoint.cpp delete mode 100644 Crawler/OverworldDisplayWindow.cpp diff --git a/Crawler/ConnectionPoint.cpp b/Crawler/ConnectionPoint.cpp new file mode 100644 index 00000000..f675fdbd --- /dev/null +++ b/Crawler/ConnectionPoint.cpp @@ -0,0 +1,11 @@ +#include "State_OverworldMap.h" + +bool ConnectionPoint::IsNeighbor(ConnectionPoint&testPoint){ + for(int neighbor:neighbors){ + if(neighbor!=-1){ + ConnectionPoint&neighborCp=State_OverworldMap::ConnectionPointFromIndex(neighbor); + if(&neighborCp==&testPoint)return true; + } + } + return false; +} \ No newline at end of file diff --git a/Crawler/ConnectionPoint.h b/Crawler/ConnectionPoint.h index 18526869..7ad6effb 100644 --- a/Crawler/ConnectionPoint.h +++ b/Crawler/ConnectionPoint.h @@ -11,4 +11,5 @@ struct ConnectionPoint{ :rect(rect),name(name),map(map),unlockCondition(unlockCondition){ neighbors.fill(-1); } + bool IsNeighbor(ConnectionPoint&testPoint); }; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index dd6ad9e5..65304675 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -387,15 +387,17 @@ void Crawler::HandleUserInput(float fElapsedTime){ void Crawler::UpdateCamera(float fElapsedTime){ lastWorldShakeAdjust=std::max(0.f,lastWorldShakeAdjust-fElapsedTime); - if(worldShakeTime-fElapsedTime>0){ + if(worldShakeTime>0){ + worldShakeTime-=fElapsedTime; + if(worldShakeTime<=0){ + camera.SetTarget(player->GetPos()); + } if(lastWorldShakeAdjust==0){ lastWorldShakeAdjust=0.02; worldShakeVel.x*=-1; worldShakeVel.y*=-1; } worldShake=player->GetPos()+worldShakeVel; - }else{ - camera.SetTarget(player->GetPos()); } worldShakeTime=std::max(0.f,worldShakeTime-fElapsedTime); camera.Update(fElapsedTime); diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 15f7ff57..9348bae0 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -323,6 +323,7 @@ + @@ -342,7 +343,6 @@ - diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index a450426a..c570c940 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -105,9 +105,6 @@ Header Files - - Header Files - Header Files @@ -231,6 +228,9 @@ Header Files + + Header Files + @@ -386,12 +386,12 @@ Source Files - - Source Files\Interface - Source Files\Interface + + Source Files + diff --git a/Crawler/OverworldDisplayWindow.cpp b/Crawler/OverworldDisplayWindow.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp index 863a691d..deefadea 100644 --- a/Crawler/State_OverworldMap.cpp +++ b/Crawler/State_OverworldMap.cpp @@ -74,7 +74,7 @@ void State_OverworldMap::Draw(Crawler*game){ } } for(ConnectionPoint&cp:connections){ - if(Unlock::IsUnlocked(cp)&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){ + if(Unlock::IsUnlocked(cp)&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)&&(&cp==currentConnectionPoint||cp.IsNeighbor(*currentConnectionPoint))){ float borderThickness=4; vf2d crosshairExtension={std::min(0.25f*cp.rect.size.x-borderThickness/2,12.f),std::min(0.25f*cp.rect.size.y-borderThickness/2,12.f)}; vf2d pulsatingAmt=vf2d{1,1}*std::abs(std::sin(currentTime*3))*2; @@ -82,28 +82,28 @@ void State_OverworldMap::Draw(Crawler*game){ vf2d pos=cp.rect.pos+vf2d{0,cp.rect.size.y-borderThickness}+vf2d{-pulsatingAmt.x,pulsatingAmt.y}; vf2d size={borderThickness+crosshairExtension.x,borderThickness}; game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x,pos.y-crosshairExtension.y}+vf2d{-pulsatingAmt.x,pulsatingAmt.y}; + pos=vf2d{pos.x,pos.y-crosshairExtension.y}; size={borderThickness,crosshairExtension.y}; game->view.FillRectDecal(pos,size,RED); //Lower-Right Corner pos=cp.rect.pos+vf2d{cp.rect.size.x-borderThickness-crosshairExtension.x,cp.rect.size.y-borderThickness}+vf2d{pulsatingAmt.x,pulsatingAmt.y}; size={borderThickness+crosshairExtension.x,borderThickness}; game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}+vf2d{pulsatingAmt.x,pulsatingAmt.y}; + pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; size={borderThickness,crosshairExtension.y}; game->view.FillRectDecal(pos,size,RED); //Upper-Left Corner pos=cp.rect.pos+vf2d{0,0}+vf2d{-pulsatingAmt.x,-pulsatingAmt.y}; size={borderThickness+crosshairExtension.x,borderThickness}; game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x,pos.y+borderThickness}+vf2d{-pulsatingAmt.x,-pulsatingAmt.y}; + pos=vf2d{pos.x,pos.y+borderThickness}; size={borderThickness,crosshairExtension.y}; game->view.FillRectDecal(pos,size,RED); //Upper-Right Corner pos=cp.rect.pos+vf2d{cp.rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulsatingAmt.x,-pulsatingAmt.y}; size={borderThickness+crosshairExtension.x,borderThickness}; game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}+vf2d{pulsatingAmt.x,-pulsatingAmt.y}; + pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; size={borderThickness,crosshairExtension.y}; game->view.FillRectDecal(pos,size,RED); break; diff --git a/Crawler/State_OverworldMap.h b/Crawler/State_OverworldMap.h index e0a6899e..3f1a10ba 100644 --- a/Crawler/State_OverworldMap.h +++ b/Crawler/State_OverworldMap.h @@ -5,7 +5,7 @@ class State_OverworldMap:public GameState{ friend class Crawler; ConnectionPoint*currentConnectionPoint; - float currentTime; + float currentTime=0; vf2d playerTargetPos; const float playerMoveSpd=48.0; public: @@ -13,7 +13,7 @@ public: static std::vectorconnections; static ConnectionPoint&GetCurrentConnectionPoint(); void SetStageMarker(std::string connectionName); - ConnectionPoint&ConnectionPointFromIndex(int ind); + static 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/Version.h b/Crawler/Version.h index a70c2410..4ff40336 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 2718 +#define VERSION_BUILD 2736 #define stringify(a) stringify_(a) #define stringify_(a) #a