diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj b/Adventures in Lestoria/Adventures in Lestoria.vcxproj index 5d9bcfec..ec73e369 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj @@ -480,6 +480,10 @@ + + + + @@ -720,6 +724,10 @@ + + + + diff --git a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters index a456dcc7..3d552ce5 100644 --- a/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters +++ b/Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters @@ -468,6 +468,9 @@ Header Files + + Header Files\State + @@ -821,6 +824,9 @@ Source Files + + Source Files\Game States + diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 2f79433d..14099497 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -1172,8 +1172,8 @@ void AiL::RenderWorld(float fElapsedTime){ for(auto it=monstersBeforeLower.begin();it!=monstersBeforeLower.end();++it){ Monster&m=**it; if(m.pos.ygroup->GetCollisionRange().middle().y){ - m.Draw(); m.strategyDraw(this,m,MONSTER_DATA[m.GetName()].GetAIStrategy()); + m.Draw(); it=monstersBeforeLower.erase(it); if(it==monstersBeforeLower.end())break; if(it!=monstersBeforeLower.begin())--it; @@ -1225,8 +1225,8 @@ void AiL::RenderWorld(float fElapsedTime){ for(auto it=monstersAfterLower.begin();it!=monstersAfterLower.end();++it){ Monster&m=**it; if(m.pos.ygroup->GetCollisionRange().middle().y){ - m.Draw(); m.strategyDraw(this,m,MONSTER_DATA[m.GetName()].GetAIStrategy()); + m.Draw(); it=monstersAfterLower.erase(it); if(it==monstersAfterLower.end())break; if(it!=monstersAfterLower.begin())--it; @@ -1277,7 +1277,8 @@ void AiL::RenderWorld(float fElapsedTime){ } #pragma endregion #pragma region Remaining Rendering - for(const Monster*const m:monstersBeforeLower){ + for(Monster*m:monstersBeforeLower){ + m->strategyDraw(this,*m,MONSTER_DATA[m->GetName()].GetAIStrategy()); m->Draw(); } for(const Bullet*const b:bulletsLower){ @@ -1297,7 +1298,8 @@ void AiL::RenderWorld(float fElapsedTime){ } RenderPlayer(player->GetPos(),{1,1}); } - for(const Monster*const m:monstersAfterLower){ + for(Monster* m:monstersAfterLower){ + m->strategyDraw(this,*m,MONSTER_DATA[m->GetName()].GetAIStrategy()); m->Draw(); } for(const int dropInd:dropsAfterLower){ @@ -1419,8 +1421,8 @@ void AiL::RenderWorld(float fElapsedTime){ for(auto it=monstersBeforeUpper.begin();it!=monstersBeforeUpper.end();++it){ Monster&m=**it; if(m.pos.ygroup->GetCollisionRange().middle().y){ - m.Draw(); m.strategyDraw(this,m,MONSTER_DATA[m.GetName()].GetAIStrategy()); + m.Draw(); it=monstersBeforeUpper.erase(it); if(it==monstersBeforeUpper.end())break; if(it!=monstersBeforeUpper.begin())--it; @@ -1472,8 +1474,8 @@ void AiL::RenderWorld(float fElapsedTime){ for(auto it=monstersAfterUpper.begin();it!=monstersAfterUpper.end();++it){ Monster&m=**it; if(m.pos.ygroup->GetCollisionRange().middle().y){ - m.Draw(); m.strategyDraw(this,m,MONSTER_DATA[m.GetName()].GetAIStrategy()); + m.Draw(); it=monstersAfterUpper.erase(it); if(it==monstersAfterUpper.end())break; if(it!=monstersAfterUpper.begin())--it; @@ -1516,7 +1518,8 @@ void AiL::RenderWorld(float fElapsedTime){ } #pragma endregion #pragma region Remaining Upper Rendering - for(const Monster*const m:monstersBeforeUpper){ + for(Monster*m:monstersBeforeUpper){ + m->strategyDraw(this,*m,MONSTER_DATA[m->GetName()].GetAIStrategy()); m->Draw(); } for(const Bullet*const b:bulletsUpper){ @@ -1536,7 +1539,8 @@ void AiL::RenderWorld(float fElapsedTime){ } RenderPlayer(player->GetPos(),{1,1}); } - for(const Monster*const m:monstersAfterUpper){ + for(Monster*m:monstersAfterUpper){ + m->strategyDraw(this,*m,MONSTER_DATA[m->GetName()].GetAIStrategy()); m->Draw(); } for(const int dropInd:dropsAfterUpper){ @@ -2028,6 +2032,7 @@ void AiL::_PrepareLevel(MapName map,MusicChange changeMusic){ GetPlayer()->ResetAccumulatedXP(); GetPlayer()->SetIframes(0.f); GetPlayer()->SetInvisible(false); + GetPlayer()->ResetVelocity(); ZONE_LIST=game->MAP_DATA[game->GetCurrentLevel()].ZoneData; return true; diff --git a/Adventures in Lestoria/Audio.cpp b/Adventures in Lestoria/Audio.cpp index ef2b464a..fc4ebffe 100644 --- a/Adventures in Lestoria/Audio.cpp +++ b/Adventures in Lestoria/Audio.cpp @@ -364,6 +364,13 @@ void Audio::SetBGMVolume(float vol){ channelListIndex++; } } +void Audio::SetBGMPitch(float pitch){ + BGM&track=Self().bgm[Self().playParams.sound]; + for(int channelListIndex=0;int trackID:track.GetChannelIDs()){ + Engine().SetPitch(trackID,pitch); + channelListIndex++; + } +} void Audio::SetSFXVolume(float vol){ sfxVol=vol; } diff --git a/Adventures in Lestoria/Audio.h b/Adventures in Lestoria/Audio.h index 0f1b5d42..deccb8d4 100644 --- a/Adventures in Lestoria/Audio.h +++ b/Adventures in Lestoria/Audio.h @@ -70,6 +70,7 @@ public: static void SetAudioEvent(const Event&eventName); static const bool BGMIsPlaying(); static const bool BGMFullyLoaded(); //Fully loaded means when the audio buffer has finished filling up, which means sound is now playing. + static void SetBGMPitch(float pitch); static void SetBGMVolume(float vol); static void SetSFXVolume(float vol); static float&GetBGMVolume(); diff --git a/Adventures in Lestoria/GameState.cpp b/Adventures in Lestoria/GameState.cpp index 0999880a..889062b6 100644 --- a/Adventures in Lestoria/GameState.cpp +++ b/Adventures in Lestoria/GameState.cpp @@ -42,6 +42,7 @@ All rights reserved. #include "State_LevelComplete.h" #include "State_Story.h" #include "State_GameHub.h" +#include "State_Death.h"; INCLUDE_game @@ -54,6 +55,7 @@ void GameState::Initialize(){ NEW_STATE(States::LEVEL_COMPLETE,State_LevelComplete); NEW_STATE(States::STORY,State_Story); NEW_STATE(States::GAME_HUB,State_GameHub); + NEW_STATE(States::DEATH,State_Death); GameState::ChangeState(States::MAIN_MENU); } diff --git a/Adventures in Lestoria/GameState.h b/Adventures in Lestoria/GameState.h index c3023185..7d7ab123 100644 --- a/Adventures in Lestoria/GameState.h +++ b/Adventures in Lestoria/GameState.h @@ -52,6 +52,7 @@ namespace States{ LEVEL_COMPLETE, STORY, KEYBIND, + DEATH, }; }; diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index e650d126..81240e98 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -717,6 +717,8 @@ bool Player::Hurt(int damage,bool onUpperLevel,float z){ } if(Menu::IsMenuOpen()&&mod_dmg>0)Menu::CloseAllMenus(); hp=std::max(0,hp-int(mod_dmg)); + + if(hp==0&&GameState::STATE!=GameState::states[States::DEATH])GameState::ChangeState(States::DEATH); hurtRumbleTime="Player.Hurt Rumble Time"_F; Input::StartVibration(); @@ -1358,4 +1360,8 @@ void Player::SetInvisible(const bool invisibleState){ const bool Player::IsInvisible()const{ return invisibility; +} + +void Player::ResetVelocity(){ + vel={}; } \ No newline at end of file diff --git a/Adventures in Lestoria/Player.h b/Adventures in Lestoria/Player.h index 565313d7..30dded4c 100644 --- a/Adventures in Lestoria/Player.h +++ b/Adventures in Lestoria/Player.h @@ -247,6 +247,7 @@ public: void SetLevel(uint8_t newLevel); void SetInvisible(const bool invisibleState); const bool IsInvisible()const; + void ResetVelocity(); private: int hp="Warrior.BaseHealth"_I; int mana="Player.BaseMana"_I; diff --git a/Adventures in Lestoria/State.h b/Adventures in Lestoria/State.h index 89ced341..04e3abb7 100644 --- a/Adventures in Lestoria/State.h +++ b/Adventures in Lestoria/State.h @@ -56,5 +56,6 @@ namespace State{ JUMP, RECOVERY, FORCE_WALK, + DEATH, }; } \ No newline at end of file diff --git a/Adventures in Lestoria/State_Death.cpp b/Adventures in Lestoria/State_Death.cpp new file mode 100644 index 00000000..19d2774d --- /dev/null +++ b/Adventures in Lestoria/State_Death.cpp @@ -0,0 +1,96 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +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 © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#include "State_Death.h" +#include "AdventuresInLestoria.h" +#include "DEFINES.h" +#include "Menu.h" +#include "ItemDrop.h" +#include "VisualNovel.h" +#include "State_OverworldMap.h" +#include "GameEvent.h" +#include "MenuComponent.h" +#include "Unlock.h" + +INCLUDE_MONSTER_LIST +INCLUDE_game + +void State_Death::OnStateChange(GameState*prevState){ + if(Menu::IsMenuOpen()){ + Menu::CloseAllMenus(); + } + game->GetPlayer()->SetState(State::DEATH); +} +void State_Death::OnLevelLoad(){ + Component(MenuType::PAUSE,"Return to Camp Button")->SetGrayedOut( + !Unlock::IsUnlocked("HUB")||game->GetCurrentMapName()=="HUB" + ); +} +void State_Death::OnUserUpdate(AiL*game){ + accTime+=game->GetElapsedTime(); + if(gameSlowdownPct<10.f){ + gameSlowdownPct+=3.f*game->GetElapsedTime(); + }else{ + game->SetMosaicEffect(1U); + } + game->view.SetZoom(util::lerp(1.f,2.f,(gameSlowdownPct-1)/10.f),game->view.WorldToScreen(game->GetPlayer()->GetPos())); + game->SetWorldColor({uint8_t(util::lerp(255,0,(gameSlowdownPct-1)/10.f)),uint8_t(util::lerp(255,0,(gameSlowdownPct-1)/10.f)),uint8_t(util::lerp(255,0,(gameSlowdownPct-1)/10.f)),255}); + Audio::SetBGMPitch(util::lerp(1.f,0,(gameSlowdownPct-1)/10.f)); + if(gameSlowdownPct<5.f){ + game->SetMosaicEffect(uint8_t(util::lerp(1.f,4.f,(gameSlowdownPct-1)/5.f))); + }else{ + game->SetMosaicEffect(uint8_t(util::lerp(4.f,1.f,(gameSlowdownPct-5)/5.f))); + } + + if(gameSlowdownPct<10.f){ + if(accTime>=1/60.f*gameSlowdownPct){ + game->SetElapsedTime(1/60.f*gameSlowdownPct); + game->HandleUserInput(game->GetElapsedTime()); + + game->UpdateEffects(game->GetElapsedTime()); + GameEvent::UpdateEvents(); + game->GetPlayer()->Update(game->GetElapsedTime()); + game->UpdateMonsters(); + + ItemDrop::UpdateDrops(game->GetElapsedTime()); + game->UpdateBullets(game->GetElapsedTime()); + //game->UpdateCamera(game->GetElapsedTime()); + accTime=0.f; + } + } +} +void State_Death::Draw(AiL*game){} \ No newline at end of file diff --git a/Adventures in Lestoria/State_Death.h b/Adventures in Lestoria/State_Death.h new file mode 100644 index 00000000..e5a5c32a --- /dev/null +++ b/Adventures in Lestoria/State_Death.h @@ -0,0 +1,51 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +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 © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#pragma once +#include "GameState.h" +#include "olcPGEX_ViewPort.h" + +class State_Death:public GameState{ +protected: + float gameSlowdownPct=1.f; + float accTime=0.f; + float zoom=1.f; + virtual void OnStateChange(GameState*prevState)override; + virtual void OnUserUpdate(AiL*game)override; + virtual void Draw(AiL*game)override; + virtual void OnLevelLoad()override; +}; \ No newline at end of file diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 73fbd548..630e45ed 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 3 #define VERSION_PATCH 0 -#define VERSION_BUILD 7646 +#define VERSION_BUILD 7662 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/olcPixelGameEngine.h b/Adventures in Lestoria/olcPixelGameEngine.h index 48952f7c..de758a06 100644 --- a/Adventures in Lestoria/olcPixelGameEngine.h +++ b/Adventures in Lestoria/olcPixelGameEngine.h @@ -1061,6 +1061,7 @@ namespace olc uint32_t GetFPS() const; // Gets last update of elapsed time float GetElapsedTime() const; + void SetElapsedTime(float elapsedTime); // Returns whether the mouse cursor exists inside the window or outside of it. const bool IsMouseInsideWindow() const; // Gets Actual Window pos @@ -2269,6 +2270,9 @@ namespace olc float PixelGameEngine::GetElapsedTime() const { return fLastElapsed; } + void PixelGameEngine::SetElapsedTime(float elapsedTime) + { fLastElapsed=elapsedTime; } + const bool PixelGameEngine::IsMouseInsideWindow() const { return GetMouseX()>=0&&GetMouseY()>=0&&GetMouseX()