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.
230 lines
9.3 KiB
230 lines
9.3 KiB
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
be used to endorse or promote products derived from this software without specific
|
|
prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
SUCH DAMAGE.
|
|
|
|
Portions of this software are copyright © 2023 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
#include "AdventuresInLestoria.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 "VisualNovel.h"
|
|
#include "State_OverworldMap.h"
|
|
#include "SaveFile.h"
|
|
#include "Audio.h"
|
|
|
|
INCLUDE_MONSTER_LIST
|
|
INCLUDE_game
|
|
|
|
std::vector<ConnectionPoint>State_OverworldMap::connections;
|
|
ConnectionPoint*State_OverworldMap::currentConnectionPoint=nullptr;
|
|
|
|
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){
|
|
game->LoadLevel("WORLD_MAP");
|
|
if(Menu::IsMenuOpen()){
|
|
Menu::CloseAllMenus();
|
|
}
|
|
game->GetPlayer()->ForceSetPos(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);
|
|
game->UpdateDiscordStatus("Overworld Map",game->GetPlayer()->GetClassName());
|
|
};
|
|
void State_OverworldMap::OnUserUpdate(AiL*game){
|
|
if(Menu::stack.size()>1)return;
|
|
|
|
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());
|
|
}
|
|
}
|
|
|
|
if(Menu::stack.size()==1&&AiL::KEY_MENU.Pressed()){
|
|
Menu::OpenMenu(OVERWORLD_MENU);
|
|
}
|
|
|
|
if(game->GetKey(S).bPressed){
|
|
Menu::OpenMenu(MERCHANT);
|
|
}
|
|
|
|
if(game->GetKey(B).bPressed){
|
|
Menu::OpenMenu(BLACKSMITH);
|
|
}
|
|
if(game->GetKey(C).bPressed){
|
|
Menu::OpenMenu(CRAFT_CONSUMABLE);
|
|
}
|
|
|
|
#pragma region Audio Test
|
|
if(game->GetKey(K1).bPressed){
|
|
Audio::Play("sfx100v2_loop_water_01.mp3"_SFX);
|
|
}
|
|
if(game->GetKey(F1).bPressed){
|
|
Audio::PlayBGM("foresty1_1");
|
|
lastAudioTime=0.f;
|
|
}else
|
|
if(game->GetKey(F2).bPressed){
|
|
Audio::PlayBGM("foresty0");
|
|
lastAudioTime=0.f;
|
|
}
|
|
if(game->GetKey(K2).bPressed){
|
|
Audio::SetAudioEvent("Default Volume");
|
|
lastEventTime=0.f;
|
|
}
|
|
if(game->GetKey(K3).bPressed){
|
|
Audio::SetAudioEvent("LowHealth");
|
|
lastEventTime=0.f;
|
|
}
|
|
if(game->GetKey(K4).bPressed){
|
|
Audio::SetAudioEvent("InCombat");
|
|
lastEventTime=0.f;
|
|
}
|
|
if(game->GetKey(K5).bPressed){
|
|
Audio::SetAudioEvent("Underwater");
|
|
lastEventTime=0.f;
|
|
}
|
|
|
|
lastEventTime=std::clamp(lastEventTime+game->GetElapsedTime(),0.f,5.0f);
|
|
lastAudioTime=std::clamp(lastAudioTime+game->GetElapsedTime(),0.f,5.0f);
|
|
#pragma endregion
|
|
|
|
#pragma region Handle Connection Point Clicking and Movement
|
|
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.unlockCondition)&&&cp==&neighbor){
|
|
UpdateCurrentConnectionPoint(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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#pragma endregion
|
|
};
|
|
void State_OverworldMap::Draw(AiL*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;
|
|
}
|
|
}
|
|
#pragma region Audio Test
|
|
std::stringstream eventText;
|
|
eventText<<"Event Set to: ";
|
|
eventText<<std::quoted(Audio::GetAudioEvent());
|
|
std::stringstream audioText;
|
|
audioText<<"Audio Track Set to: ";
|
|
audioText<<std::quoted(Audio::GetTrackName());
|
|
if(lastEventTime!=5.0f)game->DrawShadowStringPropDecal({2,game->ScreenHeight()-36.f},eventText.str(),{255,255,255,uint8_t(util::lerp(255,0,lastEventTime/5.0f))},{0,0,0,uint8_t(util::lerp(255,0,lastEventTime/5.0f))});
|
|
if(lastAudioTime!=5.0f)game->DrawShadowStringPropDecal({2,game->ScreenHeight()-20.f},audioText.str(),{255,255,255,uint8_t(util::lerp(255,0,lastAudioTime/5.0f))},{0,0,0,uint8_t(util::lerp(255,0,lastAudioTime/5.0f))});
|
|
#pragma endregion
|
|
};
|
|
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->UpdateDiscordStatus(State_OverworldMap::GetCurrentConnectionPoint().name,game->GetPlayer()->GetClassName());
|
|
SaveFile::SaveGame();
|
|
if(State_OverworldMap::GetCurrentConnectionPoint().map.starts_with("STORY")){
|
|
VisualNovel::LoadVisualNovel(State_OverworldMap::GetCurrentConnectionPoint().map);
|
|
}else{
|
|
GameState::ChangeState(States::GAME_RUN,0.3f);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void State_OverworldMap::UpdateCurrentConnectionPoint(const ConnectionPoint&connection){
|
|
currentConnectionPoint=const_cast<ConnectionPoint*>(&connection);
|
|
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);
|
|
Component<MenuComponent>(OVERWORLD_LEVEL_SELECT,"Change Loadout Button")->Enable(currentConnectionPoint->levelDataExists&&!(currentConnectionPoint->type=="STORY"||currentConnectionPoint->type=="SHOP"));
|
|
} |