From 0df1760f15267b5c44f69b02e9780b86e0d42b6a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 20 Aug 2024 04:45:50 -0500 Subject: [PATCH] Added speedometer visual and text display. --- assets/speedometer.png | Bin 0 -> 776 bytes assets/speedometer_overlay.png | Bin 0 -> 2053 bytes src/Hamster.cpp | 4 ++++ src/Hamster.h | 1 + src/HamsterGame.cpp | 40 ++++++++++++++++++++++++--------- src/HamsterGame.h | 1 + 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 assets/speedometer.png create mode 100644 assets/speedometer_overlay.png diff --git a/assets/speedometer.png b/assets/speedometer.png new file mode 100644 index 0000000000000000000000000000000000000000..72d2aacef1bebc32d5b29362c0060292cf21aff3 GIT binary patch literal 776 zcmV+j1NZ!iP)EX>4Tx04R}tkv&MmKpe$iQ>8_!g6$yUkf92KT~x%eRIvyaN?V~-2b1e3G-*gu zTpR`0f`cE6RRU2TkN3P2bzi}?vEbz>bo=MFUhls^e7t3AD%DO^4LmbX4D&-4V zhx44bI4jjUYu}Tuie$2%`V*8WilF3y8 zBgX=2P$1cU@IUz7tx=qwa*_fup!dbHKE?pwF3@UN*7vbxwN3!^`WJ_L}La_+EpV2qvfZ#3Ax90TL-pAn`v1clY-1nRb6ax7>2Vt#32K00006VoOIv08ao>0Dz+=vp@g<010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=m-=E1R2&I?hOC{02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{007`gL_t(&-tCyn4nrXbL}C8_pXs(~+UONz3W2Q-9swUg zMZ{!nx)}HRD9-@dGZViVS$~y5-v)IDq~(Br5Vuacrh8!?b2s4pxdR-VnD~Q2!jC~zak6co^`z*J+59#f4m447(+(POGHMvpJzQ$Vke(hNAr zvIbO&Uer?SPlP)EX>4Tx04R}tkv&MmKpe$iQ>8_!g6$yUkf92KT~x%eRIvyaN?V~-2b1e3G-*gu zTpR`0f`cE6RRU2TkN3P2bzi}?vEbz>bo=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nZ$G4yLec~zVeT22dnVU`w4!oy!Xhy$$4FH2OeHE$Ohi6q z#&i9m(sNX(Bm~`ew5U85Szyr#<|Cui);gxES0PDL-2L@8to(i#Trt{~HA0nd7bR*P z`;adpIzs7R)}hl-3MKK)67&4uX=~2YhgKo&q9Es~PNy(OE1uswk?fc86{U8hfSp%;wUwGa{Qy`*Lg-;Suhbv*Dk jB!9yO@Gt53U)%5}LKi{8(q$0B00000NkvXXu0mjfqwBfe literal 0 HcmV?d00001 diff --git a/src/Hamster.cpp b/src/Hamster.cpp index ad6d8a5..abec064 100644 --- a/src/Hamster.cpp +++ b/src/Hamster.cpp @@ -522,4 +522,8 @@ void Hamster::Knockout(){ state=KNOCKOUT; knockoutTimer=4.f; animations.ChangeState(internalAnimState,HamsterGame::KNOCKOUT); +} + +const float Hamster::GetSpeed()const{ + return vel.mag(); } \ No newline at end of file diff --git a/src/Hamster.h b/src/Hamster.h index de183ea..f9196ad 100644 --- a/src/Hamster.h +++ b/src/Hamster.h @@ -148,4 +148,5 @@ public: const vf2d GetNearestSafeLocation()const; void SetJetFuel(const float amt); void Knockout(); + const float GetSpeed()const; }; \ No newline at end of file diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index cb405a6..6bb2c17 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -53,6 +53,8 @@ void HamsterGame::LoadGraphics(){ _LoadImage("fuelmeter.png"); _LoadImage("fuelbar.png"); _LoadImage("fuelbar_outline.png"); + _LoadImage("speedometer.png"); + _LoadImage("speedometer_overlay.png"); UpdateMatrixTexture(); } @@ -137,6 +139,8 @@ void HamsterGame::LoadLevel(const std::string_view mapName){ } void HamsterGame::UpdateGame(const float fElapsedTime){ + vEye.z+=(Hamster::GetPlayer().GetZ()+zoom-vEye.z)*fLazyFollowRate*fElapsedTime; + speedometerDisplayAmt+=(Hamster::GetPlayer().GetSpeed()-speedometerDisplayAmt)*fLazyFollowRate*fElapsedTime; UpdateMatrixTexture(); UpdateWaterTexture(); cloudOffset+=cloudSpd*fElapsedTime; @@ -185,15 +189,34 @@ void HamsterGame::DrawGame(){ } #pragma endregion #pragma region Drown/Burn Bar. - if(Hamster::GetPlayer().IsDrowning()){ - DrawDecal({12.f,240.f},GetGFX("drownmeter.png").Decal()); - GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetDrownRatio()*57.f,4.f},{145,199,255},{226,228,255},{226,228,255},{145,199,255}); - } - else if(Hamster::GetPlayer().IsBurning()){ - DrawDecal({12.f,240.f},GetGFX("burnmeter.png").Decal()); - GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetBurnRatio()*57.f,4.f},{250,177,163},{226,228,255},{226,228,255},{250,177,163}); + { + if(Hamster::GetPlayer().IsDrowning()){ + DrawDecal({12.f,240.f},GetGFX("drownmeter.png").Decal()); + GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetDrownRatio()*57.f,4.f},{145,199,255},{226,228,255},{226,228,255},{145,199,255}); + } + else if(Hamster::GetPlayer().IsBurning()){ + DrawDecal({12.f,240.f},GetGFX("burnmeter.png").Decal()); + GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetBurnRatio()*57.f,4.f},{250,177,163},{226,228,255},{226,228,255},{250,177,163}); + } } #pragma endregion + float speedometerWidth{float(GetGFX("speedometer.png").Sprite()->width)}; + const float speedometerSpd{std::min(speedometerWidth,speedometerDisplayAmt/180.f*speedometerWidth)}; + DrawPartialRotatedDecal(SCREEN_FRAME.pos+SCREEN_FRAME.size+vf2d{48.f,-4.f-GetGFX("speedometer_overlay.png").Sprite()->height},GetGFX("speedometer_overlay.png").Decal(),0.f,GetGFX("speedometer_overlay.png").Sprite()->Size()/2,{},vf2d{speedometerSpd,float(GetGFX("speedometer_overlay.png").Sprite()->height)}); + DrawRotatedDecal(SCREEN_FRAME.pos+SCREEN_FRAME.size+vf2d{48.f,-4.f-GetGFX("speedometer.png").Sprite()->height},GetGFX("speedometer.png").Decal(),0.f,GetGFX("speedometer.png").Sprite()->Size()/2); + const std::string speedometerStr{std::format("{:.0f}km/h",speedometerDisplayAmt)}; + const vf2d speedometerStrSize{GetTextSize(speedometerStr)}; + Pixel speedometerCol{CYAN}; + if(speedometerDisplayAmt>=180)speedometerCol=RED; + else if(speedometerDisplayAmt>=120)speedometerCol=YELLOW; + else if(speedometerDisplayAmt>=80)speedometerCol=GREEN; + for(int y:std::ranges::iota_view(-1,2)){ + for(int x:std::ranges::iota_view(-1,2)){ + if(x==0&&y==0)continue; + DrawStringDecal(SCREEN_FRAME.pos+SCREEN_FRAME.size-speedometerStrSize-vf2d{4.f,4.f}+vi2d{x,y},speedometerStr,BLACK); + } + } + DrawStringDecal(SCREEN_FRAME.pos+SCREEN_FRAME.size-speedometerStrSize-vf2d{4.f,4.f},speedometerStr,speedometerCol); } const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{ @@ -247,9 +270,6 @@ void HamsterGame::DrawLevelTiles(){ bool HamsterGame::OnUserUpdate(float fElapsedTime){ runTime+=fElapsedTime; - - vEye.z+=(Hamster::GetPlayer().GetZ()+zoom-vEye.z)*fLazyFollowRate*fElapsedTime; - UpdateGame(fElapsedTime); DrawGame(); return true; diff --git a/src/HamsterGame.h b/src/HamsterGame.h index 2fab5d7..d595d0a 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -118,4 +118,5 @@ private: const float fLazyFollowRate{4.0f}; vf2d cloudSpd{}; vf2d cloudOffset{}; + float speedometerDisplayAmt{0.f}; }; \ No newline at end of file