|
|
|
#pragma once
|
|
|
|
#include "State_OverworldMap.h"
|
|
|
|
#include "Crawler.h"
|
|
|
|
#include "DEFINES.h"
|
|
|
|
#include "Menu.h"
|
|
|
|
#include "Unlock.h"
|
|
|
|
#include "ConnectionPoint.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "MenuLabel.h"
|
|
|
|
#include "EncountersSpawnListScrollableWindowComponent.h"
|
|
|
|
|
|
|
|
INCLUDE_MONSTER_LIST
|
|
|
|
INCLUDE_game
|
|
|
|
|
|
|
|
std::vector<ConnectionPoint>State_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.
|
|
|
|
}
|
|
|
|
void State_OverworldMap::OnStateChange(GameState*prevState){
|
|
|
|
if(Menu::IsMenuOpen()){
|
|
|
|
Menu::CloseAllMenus();
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
game->camera.MoveCamera(currentConnectionPoint->rect.middle()+vf2d{game->GetScreenSize().x/6.0f,0});
|
|
|
|
COMPONENT(MenuLabel,OVERWORLD_LEVEL_SELECT,"Chapter Label")->SetLabel("Chapter "+std::to_string(game->GetCurrentChapter()));
|
|
|
|
COMPONENT(MenuLabel,OVERWORLD_LEVEL_SELECT,"Stage Label")->SetLabel(currentConnectionPoint->name);
|
|
|
|
COMPONENT(EncountersSpawnListScrollableWindowComponent,OVERWORLD_LEVEL_SELECT,"Spawns List")->UpdateSpawns(currentConnectionPoint->spawns);
|
|
|
|
Menu::OpenMenu(OVERWORLD_LEVEL_SELECT,false);
|
|
|
|
};
|
|
|
|
void State_OverworldMap::OnUserUpdate(Crawler*game){
|
|
|
|
game->camera.SetTarget(currentConnectionPoint->rect.middle()+vf2d{game->GetScreenSize().x/6.0f,0});
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
COMPONENT(MenuLabel,OVERWORLD_LEVEL_SELECT,"Stage Label")->SetLabel(currentConnectionPoint->name);
|
|
|
|
COMPONENT(EncountersSpawnListScrollableWindowComponent,OVERWORLD_LEVEL_SELECT,"Spawns List")->UpdateSpawns(currentConnectionPoint->spawns);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
void State_OverworldMap::Draw(Crawler*game){
|
|
|
|
currentTime+=game->GetElapsedTime();
|
|
|
|
for(ConnectionPoint&cp:connections){
|
|
|
|
if(!Unlock::IsUnlocked(cp)){
|
|
|
|
game->view.FillRectDecal(cp.rect.pos,cp.rect.size,{0,0,0,128});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(ConnectionPoint&cp:connections){
|
|
|
|
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;
|
|
|
|
//Lower-Left Corner
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
size={borderThickness,crosshairExtension.y};
|
|
|
|
game->view.FillRectDecal(pos,size,RED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
void State_OverworldMap::SetStageMarker(std::string connectionName){
|
|
|
|
for(ConnectionPoint&connection:connections){
|
|
|
|
if(connection.name==connectionName){
|
|
|
|
currentConnectionPoint=&connection;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ERR("WARNING! Could not find a connection point with name "<<connectionName<<"!");
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionPoint&State_OverworldMap::ConnectionPointFromIndex(int ind){
|
|
|
|
return connections.at(ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionPoint&State_OverworldMap::GetCurrentConnectionPoint(){
|
|
|
|
return *((State_OverworldMap*)(GameState::states.at(States::OVERWORLD_MAP)))->currentConnectionPoint;
|
|
|
|
}
|