From a16dc51d23ed1c9fe2681f7ddb2fef67f14928cb Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 19 Aug 2024 17:37:02 -0500 Subject: [PATCH] Hamster landing speed controls. --- src/Hamster.cpp | 6 +++++- src/Hamster.h | 1 + src/HamsterGame.cpp | 4 +++- src/HamsterJet.cpp | 16 ++++++++++++++++ src/HamsterJet.h | 1 + 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Hamster.cpp b/src/Hamster.cpp index fc2f583..118ed76 100644 --- a/src/Hamster.cpp +++ b/src/Hamster.cpp @@ -215,6 +215,10 @@ void Hamster::DrawHamsters(TransformedView&tv){ } } +void Hamster::DrawOverlay(){ + if(GetPlayer().hamsterJet.has_value())GetPlayer().hamsterJet.value().DrawOverlay(); +} + const Animate2D::Frame&Hamster::GetCurrentAnimation()const{ return animations.GetFrame(internalAnimState); } @@ -307,7 +311,7 @@ void Hamster::HandleCollision(){ } } for(Powerup&powerup:Powerup::GetPowerups()){ - if(!HasPowerup(powerup.GetType())&&geom2d::overlaps(geom2d::circle(GetPos(),collisionRadius),geom2d::circle(powerup.GetPos(),20.f))){ + if(z<=0.1f&&!HasPowerup(powerup.GetType())&&geom2d::overlaps(geom2d::circle(GetPos(),collisionRadius),geom2d::circle(powerup.GetPos(),20.f))){ ObtainPowerup(powerup.GetType()); powerup.OnPowerupObtain(); } diff --git a/src/Hamster.h b/src/Hamster.h index dbbd022..22f4f26 100644 --- a/src/Hamster.h +++ b/src/Hamster.h @@ -109,6 +109,7 @@ public: static void UpdateHamsters(const float fElapsedTime); static void LoadHamsters(const vf2d startingLoc); static void DrawHamsters(TransformedView&tv); + static void DrawOverlay(); const Animate2D::Frame&GetCurrentAnimation()const; const vf2d&GetPos()const; const float&GetZ()const; diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index d7698da..f2c4f48 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -48,6 +48,8 @@ void HamsterGame::LoadGraphics(){ _LoadImage("dot.png"); _LoadImage("clouds.png"); _LoadImage("aimingTarget.png"); + _LoadImage("fallometer.png"); + _LoadImage("fallometer_outline.png"); UpdateMatrixTexture(); } @@ -158,7 +160,7 @@ void HamsterGame::DrawGame(){ tv.DrawPartialDecal({-3200,-3200},currentMap.value().GetData().GetMapData().MapSize*16+vf2d{6400,6400},GetGFX("clouds.png").Decal(),cloudOffset*2,currentMap.value().GetData().GetMapData().MapSize*16/2.f,{255,255,255,72}); SetZ(0.f); border.Draw(); - + Hamster::DrawOverlay(); #pragma region Powerup Display for(int y:std::ranges::iota_view(0,4)){ for(int x:std::ranges::iota_view(0,2)){ diff --git a/src/HamsterJet.cpp b/src/HamsterJet.cpp index b63c678..9fa16e2 100644 --- a/src/HamsterJet.cpp +++ b/src/HamsterJet.cpp @@ -175,6 +175,12 @@ void HamsterJet::HandleJetControls(){ hamster.vel=vf2d{std::min(hamster.GetMaxSpeed(),hamster.vel.polar().x),hamster.vel.polar().y}.cart(); hamster.frictionEnabled=false; } + if(HamsterGame::Game().GetKey(UP).bHeld){ + fallSpd=std::min(5.f,fallSpd+5.f*HamsterGame::Game().GetElapsedTime()); + } + if(HamsterGame::Game().GetKey(DOWN).bHeld){ + fallSpd=std::max(1.f,fallSpd-5.f*HamsterGame::Game().GetElapsedTime()); + } if(HamsterGame::Game().GetKey(SPACE).bPressed){ if(lastTappedSpace<=0.6f){ state=LANDING; @@ -185,4 +191,14 @@ void HamsterJet::HandleJetControls(){ const HamsterJet::State HamsterJet::GetState()const{ return state; +} + +void HamsterJet::DrawOverlay()const{ + if(state==LANDING){ + HamsterGame::Game().DrawDecal(HamsterGame::SCREEN_FRAME.pos,HamsterGame::GetGFX("fallometer_outline.png").Decal()); + float meterStartY{68.f}; + float meterEndY{223.f}; + float meterHeight{meterEndY-meterStartY}; + HamsterGame::Game().DrawPartialDecal(HamsterGame::SCREEN_FRAME.pos+vf2d{0,222}-vf2d{0,(fallSpd/5.f)*meterHeight},HamsterGame::GetGFX("fallometer.png").Decal(),vf2d{0,223}-vf2d{0,(fallSpd/5.f)*meterHeight},vf2d{float(HamsterGame::GetGFX("fallometer.png").Sprite()->width),(fallSpd/5.f)*meterHeight}); + } } \ No newline at end of file diff --git a/src/HamsterJet.h b/src/HamsterJet.h index 819b2a7..b3b7de5 100644 --- a/src/HamsterJet.h +++ b/src/HamsterJet.h @@ -81,6 +81,7 @@ public: HamsterJet(Hamster&hamster); void Update(const float fElapsedTime); void Draw(); + void DrawOverlay()const; void HandleJetControls(); const State GetState()const; }; \ No newline at end of file