The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.8 KiB
114 lines
4.8 KiB
#pragma once
|
|
#include "State_OverworldMap.h"
|
|
#include "Crawler.h"
|
|
#include "DEFINES.h"
|
|
#include "Menu.h"
|
|
#include "Unlock.h"
|
|
#include "ConnectionPoint.h"
|
|
#include "util.h"
|
|
#include "drawutil.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);
|
|
Component<MenuComponent>(OVERWORLD_LEVEL_SELECT,"Enter Button")->Enable(currentConnectionPoint->levelDataExists);
|
|
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);
|
|
Component<MenuComponent>(OVERWORLD_LEVEL_SELECT,"Enter Button")->Enable(currentConnectionPoint->levelDataExists);
|
|
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))){
|
|
drawutil::DrawCrosshairDecalTransformedView(game->view,cp.rect,currentTime);
|
|
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;
|
|
}
|
|
|
|
void State_OverworldMap::StartLevel(){
|
|
game->LoadLevel(LEVEL_NAMES.at(State_OverworldMap::GetCurrentConnectionPoint().map));
|
|
GameState::ChangeState(States::GAME_RUN);
|
|
} |