Remove unused assets, don't reload the same map unnecessarily.

sigonasr2 3 months ago
parent 8c5f326fa8
commit 448ef6a64d
  1. 1
      .gitignore
  2. 1
      assets/PBData
  3. BIN
      assets/nene - Boss Battle #3 Alternate.ogg
  4. BIN
      assets/nene - Boss Battle #5 V2.ogg
  5. 32
      src/HamsterGame.cpp
  6. 2
      src/HamsterGame.h
  7. 2
      src/HamsterNet.cpp
  8. 27
      src/Menu.cpp
  9. 2
      src/Menu.h

1
.gitignore vendored

@ -31,3 +31,4 @@ vs-build
/CMakeCache.txt
/cmake_install.cmake
/hamster.vcxproj.user
PBData

@ -1 +0,0 @@
38582 54006 53138 73057 148356 87387 78955 84865 121992 82685 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 1 0.6 OneLoneHam Black

@ -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<int>::max()){
return Hamster::GetPlayer().GetFinishedTime();
}else return net.GetCurrentRaceTime();
}
const bool HamsterGame::RaceCountdownCompleted(){

@ -222,4 +222,6 @@ private:
int lastDigitPlayedSound{};
float playerDifferentialTime{};
float holdEscTimer{0.f};
std::optional<int>racePauseTime{};
bool raceStarted{false};
};

@ -310,7 +310,7 @@ std::pair<HamsterNet::FinishTime,bool> HamsterNet::FinishRace()
std::chrono::duration<double, std::milli> duration = m_tp2 - m_tp1;
m_time = static_cast<int>(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()

@ -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::vector<Menu::Button>Menu::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&&currentMenu!=GAMEPLAY_RESULTS&&currentMenu!=AFTER_RACE_MENU&&currentMenu!=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::vector<int>pointTable{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);

@ -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<Button>GetMenuButtons(const MenuType type);
bool ignoreInputs{false};
std::vector<LeaderboardEntry>loadedLeaderboard;

Loading…
Cancel
Save