Add countdown timer.

sigonasr2 3 months ago
parent 363ad229bb
commit 92f2b4dd85
  1. BIN
      assets/countdown.png
  2. 1
      src/AnimationState.h
  3. 1
      src/Hamster.cpp
  4. 12
      src/HamsterGame.cpp
  5. 2
      src/HamsterGame.h
  6. 1
      src/TODO.txt

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

@ -48,5 +48,6 @@ namespace AnimationState{
CHECKPOINT_CYCLING, CHECKPOINT_CYCLING,
CHECKPOINT_COLLECTED, CHECKPOINT_COLLECTED,
SIDE_VIEW, SIDE_VIEW,
COUNTDOWN,
}; };
} }

@ -669,6 +669,7 @@ const float Hamster::GetMaxSpeed()const{
}break; }break;
} }
} }
if(!HamsterGame::Game().RaceCountdownCompleted())finalMaxSpd*=0.f;
return finalMaxSpd; return finalMaxSpd;
} }
const float Hamster::GetFriction()const{ const float Hamster::GetFriction()const{

@ -140,6 +140,7 @@ void HamsterGame::LoadAnimations(){
LoadAnimation(AnimationState::DEFAULT,"checkpoint.png",{{}},0.f,Animate2D::Style::OneShot,{128,128}); LoadAnimation(AnimationState::DEFAULT,"checkpoint.png",{{}},0.f,Animate2D::Style::OneShot,{128,128});
LoadAnimation(AnimationState::CHECKPOINT_CYCLING,"checkpoint.png",{{},{128,0}},0.4f,Animate2D::Style::Repeat,{128,128}); LoadAnimation(AnimationState::CHECKPOINT_CYCLING,"checkpoint.png",{{},{128,0}},0.4f,Animate2D::Style::Repeat,{128,128});
LoadAnimation(AnimationState::CHECKPOINT_COLLECTED,"checkpoint.png",{{128,0}},0.f,Animate2D::Style::OneShot,{128,128}); LoadAnimation(AnimationState::CHECKPOINT_COLLECTED,"checkpoint.png",{{128,0}},0.f,Animate2D::Style::OneShot,{128,128});
LoadAnimation(AnimationState::COUNTDOWN,"countdown.png",{{0,0},{32,0},{64,0}},1.f,Animate2D::Style::OneShot,{32,32});
} }
void HamsterGame::LoadLevel(const std::string&mapName){ void HamsterGame::LoadLevel(const std::string&mapName){
@ -198,9 +199,11 @@ void HamsterGame::LoadLevel(const std::string&mapName){
audio.Play(bgm.at(currentMap.value().GetData().GetBGM()),true); audio.Play(bgm.at(currentMap.value().GetData().GetBGM()),true);
Hamster::MoveHamstersToSpawn(currentMap.value().GetData().GetSpawnZone()); Hamster::MoveHamstersToSpawn(currentMap.value().GetData().GetSpawnZone());
countdownTimer=3.f;
} }
void HamsterGame::UpdateGame(const float fElapsedTime){ void HamsterGame::UpdateGame(const float fElapsedTime){
countdownTimer=std::max(0.f,countdownTimer-fElapsedTime);
vEye.z+=(Hamster::GetPlayer().GetZ()+zoom-vEye.z)*fLazyFollowRate*fElapsedTime; vEye.z+=(Hamster::GetPlayer().GetZ()+zoom-vEye.z)*fLazyFollowRate*fElapsedTime;
speedometerDisplayAmt+=(Hamster::GetPlayer().GetSpeed()-speedometerDisplayAmt)*fLazyFollowRate*fElapsedTime; speedometerDisplayAmt+=(Hamster::GetPlayer().GetSpeed()-speedometerDisplayAmt)*fLazyFollowRate*fElapsedTime;
@ -308,6 +311,11 @@ void HamsterGame::DrawGame(){
DrawDecal({2.f,4.f},GetGFX("radar.png").Decal()); DrawDecal({2.f,4.f},GetGFX("radar.png").Decal());
DrawRadar(); DrawRadar();
DrawStringDecal({0,8.f},std::to_string(GetFPS())); DrawStringDecal({0,8.f},std::to_string(GetFPS()));
if(countdownTimer>0.f){
Pixel timerColor{fmod(countdownTimer,1.f)<0.5f?GREEN:WHITE};
timerColor.a=util::lerp(0.f,1.f,fmod(countdownTimer,1.f))*255;
DrawPartialRotatedDecal(SCREEN_FRAME.middle(),GetGFX("countdown.png").Decal(),0.f,{16.f,16.f},{int(countdownTimer)*32.f,0.f},{32,32},{4.f,4.f},timerColor);
}
} }
const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{ const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{
@ -665,6 +673,10 @@ const int HamsterGame::GetRaceTime(){
return net.GetCurrentRaceTime(); return net.GetCurrentRaceTime();
} }
const bool HamsterGame::RaceCountdownCompleted(){
return countdownTimer==0.f;
}
int main() int main()
{ {
HamsterGame game("Project Hamster"); HamsterGame game("Project Hamster");

@ -102,6 +102,7 @@ public:
static void SavePB(const std::string&mapName,int ms); static void SavePB(const std::string&mapName,int ms);
static void LoadPBs(); static void LoadPBs();
const int GetRaceTime(); const int GetRaceTime();
const bool RaceCountdownCompleted();
private: private:
void UpdateGame(const float fElapsedTime); void UpdateGame(const float fElapsedTime);
void DrawGame(); void DrawGame();
@ -141,6 +142,7 @@ private:
std::unordered_map<std::string,int>bgm; std::unordered_map<std::string,int>bgm;
GameMode mode{GameMode::SINGLE_RACE}; GameMode mode{GameMode::SINGLE_RACE};
HamsterNet net; HamsterNet net;
float countdownTimer{};
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
#ifndef __DEBUG__ #ifndef __DEBUG__
SplashScreen splash; SplashScreen splash;

@ -167,6 +167,7 @@ Hamster Jet Landing Sound
Powerup Collection Sound Powerup Collection Sound
Hamster Wheel Boost Sound Hamster Wheel Boost Sound
Checkpoint Collection Sound Checkpoint Collection Sound
Countdown Sound Effect
Hamster Jet Launch Command Sound Hamster Jet Launch Command Sound
Fail to Boost/Jet Launch command sound Fail to Boost/Jet Launch command sound

Loading…
Cancel
Save