Navigation between unlocked stages is now possible.

This commit is contained in:
2023-11-04 22:19:25 -05:00
parent 54614d31dc
commit 4f65d2240a
11 changed files with 136 additions and 9 deletions
+47 -1
View File
@@ -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<float>(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&&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 "<<connectionName<<"!"<<std::endl;
throw;
}
ConnectionPoint&State_OverworldMap::ConnectionPointFromIndex(int ind){
return connections.at(ind);
}
ConnectionPoint&State_OverworldMap::GetCurrentConnectionPoint(){
return *((State_OverworldMap*)(GameState::states.at(States::OVERWORLD_MAP)))->currentConnectionPoint;
}