diff --git a/.gitignore b/.gitignore index a6a541b..2559803 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ vs-build /CMakeCache.txt /cmake_install.cmake /hamster.vcxproj.user +PBData \ No newline at end of file diff --git a/assets/PBData b/assets/PBData deleted file mode 100644 index ebe0295..0000000 --- a/assets/PBData +++ /dev/null @@ -1 +0,0 @@ -38582 54006 53138 73057 148356 87387 78955 84865 121992 82685 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 1 0.6 OneLoneHam Black \ No newline at end of file diff --git a/assets/nene - Boss Battle #3 Alternate.ogg b/assets/nene - Boss Battle #3 Alternate.ogg deleted file mode 100644 index d19db5b..0000000 Binary files a/assets/nene - Boss Battle #3 Alternate.ogg and /dev/null differ diff --git a/assets/nene - Boss Battle #5 V2.ogg b/assets/nene - Boss Battle #5 V2.ogg deleted file mode 100644 index b344203..0000000 Binary files a/assets/nene - Boss Battle #5 V2.ogg and /dev/null differ diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index 7511f83..1fcdaac 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -89,8 +89,6 @@ bool HamsterGame::OnUserCreate(){ LoadSound("shiru8bit - Proper Summer.ogg"); LoadSound("shiru8bit - Enchanted Woods.ogg"); LoadSound("shiru8bit - A Little Journey.ogg"); - LoadSound("nene - Boss Battle #3 Alternate.ogg"); - LoadSound("nene - Boss Battle #5 V2.ogg"); border.ChangeBorder(Border::DEFAULT); @@ -210,7 +208,9 @@ void HamsterGame::LoadAnimations(){ } void HamsterGame::LoadLevel(const std::string&mapName){ + raceStarted=false; currentMap=TMXParser{ASSETS_DIR+mapName}; + std::string previousMapName=currentMapName; currentMapName=mapName; cloudSpd.x=util::random_range(-12.f,12.f); cloudSpd.y=util::random_range(-0.3f,0.3f); @@ -221,11 +221,7 @@ void HamsterGame::LoadLevel(const std::string&mapName){ camera.SetTarget(currentMap.value().GetData().GetSpawnZone().middle()); camera.Update(0.f); camera.SetMode(Camera2D::Mode::LazyFollow); - - mapImage.Create(currentMap.value().GetData().GetMapData().width*16,currentMap.value().GetData().GetMapData().height*16); - mapPowerupsTemp.clear(); - checkpointsTemp.clear(); totalOperationsCount=0; for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){ @@ -235,10 +231,19 @@ void HamsterGame::LoadLevel(const std::string&mapName){ loadingMapLayerInd=0U; loadingMapLayerTileY=0U; - SetDrawTarget(mapImage.Sprite()); - Clear(BLANK); - - ProcessMap(); + if(previousMapName!=currentMapName){ + mapImage.Create(currentMap.value().GetData().GetMapData().width*16,currentMap.value().GetData().GetMapData().height*16); + mapPowerupsTemp.clear(); + checkpointsTemp.clear(); + SetDrawTarget(mapImage.Sprite()); + Clear(BLANK); + + ProcessMap(); + }else{ + operationsProgress=totalOperationsCount; + menu.UpdateLoadingProgress(1.f); + menu.OnLevelLoaded(); + } } void HamsterGame::UpdateGame(const float fElapsedTime){ @@ -247,6 +252,7 @@ void HamsterGame::UpdateGame(const float fElapsedTime){ if(countdownTimer<=0.f){ countdownTimer=0.f; PlaySFX("start_race_whistle.wav"); + raceStarted=true; leaderboard.OnRaceStart(); net.StartRace(currentMapName); }else if(int(countdownTimer)!=lastDigitPlayedSound){ @@ -729,7 +735,11 @@ void HamsterGame::LoadRace(const std::string&mapName){ } const int HamsterGame::GetRaceTime(){ - return net.GetCurrentRaceTime(); + if(!raceStarted)return 0; + if(racePauseTime.has_value())return racePauseTime.value(); + if(Hamster::GetPlayer().GetFinishedTime()!=std::numeric_limits::max()){ + return Hamster::GetPlayer().GetFinishedTime(); + }else return net.GetCurrentRaceTime(); } const bool HamsterGame::RaceCountdownCompleted(){ diff --git a/src/HamsterGame.h b/src/HamsterGame.h index 242f379..ef14ec7 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -222,4 +222,6 @@ private: int lastDigitPlayedSound{}; float playerDifferentialTime{}; float holdEscTimer{0.f}; + std::optionalracePauseTime{}; + bool raceStarted{false}; }; diff --git a/src/HamsterNet.cpp b/src/HamsterNet.cpp index 855b110..43a8f27 100644 --- a/src/HamsterNet.cpp +++ b/src/HamsterNet.cpp @@ -310,7 +310,7 @@ std::pair HamsterNet::FinishRace() std::chrono::duration duration = m_tp2 - m_tp1; m_time = static_cast(duration.count()); - return {m_time,(hamsterNet__finishRace(m_map.c_str(), m_color.c_str(), m_time - m_pause_time) == 1)}; + return {m_time - m_pause_time,(hamsterNet__finishRace(m_map.c_str(), m_color.c_str(), m_time - m_pause_time) == 1)}; } bool HamsterNet::StartPause() diff --git a/src/Menu.cpp b/src/Menu.cpp index 49d6e75..a97bd8b 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -73,10 +73,11 @@ void Menu::UpdateAndDraw(HamsterGame&game,const float fElapsedTime){ menuTimer-=fElapsedTime; if(menuTimer<=0.f){ menuTimer=0.f; + MenuType previousMenu=currentMenu; currentMenu=nextMenu; oldLayerPos={}; newLayerPos=game.SCREEN_FRAME.pos; - OnMenuTransition(); + OnMenuTransition(previousMenu); } } @@ -95,20 +96,13 @@ void Menu::UpdateAndDraw(HamsterGame&game,const float fElapsedTime){ case MAIN_MENU:{ }break; case GAMEPLAY:{ - //if(game.GetKey(ESCAPE).bPressed)Transition(TransitionType::FADE_OUT,PAUSE,0.1f); + if(game.GetKey(ESCAPE).bPressed){ + game.net.StartPause(); + game.racePauseTime=HamsterGame::Game().GetRaceTime(); + Transition(TransitionType::FADE_OUT,PAUSE,0.1f); + } game.UpdateGame(fElapsedTime); game.DrawGame(); - if(game.GetKey(ESCAPE).bHeld){ - uint8_t alpha{uint8_t(abs(sin(float(geom2d::pi)*HamsterGame::Game().GetRuntime()))*255)}; - game.DrawShadowStringDecal(game.SCREEN_FRAME.pos+vf2d{2.f,2.f},"Keep Holding Esc to Restart...",{255,255,0,alpha},{0,0,0,alpha},{2.f,2.f}); - game.holdEscTimer+=fElapsedTime; - if(game.holdEscTimer>3.f){ - game.holdEscTimer=0.f; - Transition(TransitionType::FADE_OUT,LOADING,0.1f); - } - }else{ - game.holdEscTimer=0.f; - } }break; case PAUSE:{ if(game.GetKey(ESCAPE).bPressed)Transition(TransitionType::FADE_OUT,GAMEPLAY,0.1f); @@ -366,13 +360,17 @@ std::vectorMenu::GetMenuButtons(const MenuType type){ } return buttons; } -void Menu::OnMenuTransition(){ +void Menu::OnMenuTransition(MenuType previousMenu){ selectedButton.reset(); menuButtons.clear(); newMenuButtons.clear(); menuButtons=GetMenuButtons(currentMenu); if(currentMenu!=GAMEPLAY&¤tMenu!=GAMEPLAY_RESULTS&¤tMenu!=AFTER_RACE_MENU&¤tMenu!=PAUSE)HamsterGame::Game().audio.Play(HamsterGame::Game().bgm["Trevor Lentz - Guinea Pig Hero.ogg"]); switch(currentMenu){ + case GAMEPLAY:{ + HamsterGame::Game().racePauseTime.reset(); + if(previousMenu==PAUSE)HamsterGame::Game().net.EndPause(); + }break; case GAMEPLAY_RESULTS:{ const std::vectorpointTable{10,7,5,3,2,1}; for(size_t ind{0};const auto&[finishTime,hamsterInd]:HamsterGame::Game().racerList){ @@ -591,6 +589,7 @@ void Menu::OnLevelLoaded(){ HamsterGame::Game().holdEscTimer=0.f; HamsterGame::Game().obtainedNewPB=false; HamsterGame::Game().mapImage.Decal()->Update(); + HamsterGame::Game().racePauseTime.reset(); Powerup::Initialize(HamsterGame::Game().mapPowerupsTemp); Checkpoint::Initialize(HamsterGame::Game().checkpointsTemp); diff --git a/src/Menu.h b/src/Menu.h index 97b0c38..ccf6477 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -108,7 +108,7 @@ private: int lastHovered{}; void Draw(HamsterGame&game,const MenuType menu,const vi2d pos); void DrawTransition(HamsterGame&game); - void OnMenuTransition(); + void OnMenuTransition(MenuType previousMenu); std::vector