From 8720d20b82492a18b73c86822b945154cfca41c9 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 19 Aug 2024 14:57:12 -0500 Subject: [PATCH] Moved Hamster Jet camera down, added targeting indicator, fix ground detection issues while in the air. --- assets/aimingTarget.png | Bin 0 -> 1235 bytes src/Hamster.cpp | 17 +++++++++++------ src/Hamster.h | 2 ++ src/HamsterGame.cpp | 5 +++++ src/HamsterGame.h | 1 + src/HamsterJet.cpp | 29 ++++++++++++++++++++--------- src/HamsterJet.h | 1 + src/TODO.txt | 21 +++++++++++++++++++++ 8 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 assets/aimingTarget.png diff --git a/assets/aimingTarget.png b/assets/aimingTarget.png new file mode 100644 index 0000000000000000000000000000000000000000..c86f878f444168c9e22db12bebca776a10d410a7 GIT binary patch literal 1235 zcmV;^1T6cBP)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#32K00006VoOIv03-k=06I6$(OUoj010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=m--N6(J#`Yn%W802y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00OH?L_t(|+T~k4PD3#aZmf5ds^Sc9;S60WvBM3Dm^eW@ zZ~%5B7S6!J5m1FV3esa~P!#eKC;rJx6RAtvIQ~96wqqr$Rp-NKEwtW@hn)X^e|_9H zO+X0n&GqvhGxz2F_NYb3AjxhBa0r|~$Dfy)(~JkCtXVRrDghydrS~rPngdml({}gg zu2*lb$CbkH*IaMLLn#S{Vgaj&3tZC!IMz2@R@X{f+`5?31vRZ+;tg1x3;S_0GUmI8(>-hKSx5U!USxJX#splSBqhe1i-p}ivzP2 z03)C!>&Lc2Q4nkqe2(rz%KF-!Aqm1`Sd6AcLcz86mK(I)axS=@w!8glyW49AT@!Lm zE(`cFefPKPgud6%=iiTycb`*k_cpc|MW#EKQzu^^klgFoE^usE8C)b}r$MUXl#Z^Q z%Ryu`2uiT)0x#LaHV#O&#BCoDe2Z}h8cG23=W`j##R_v)lgRTN>61!=j}f>lF$wTo zvP0NJf?!55Go3%2GMAAB5S}!h3o(--L9#R!BcPQbMgSsM8D|R^qO4^RkP)m5_CzWb zT!EWy$=-G~-@%DLoGRawO8U zSQg+o$#I-0t7HMoE{Eb)hWH(!URz@7UEx?$)PAqo74E(*Zm_PRRU%8ShnBtGjEA3x zr%AE~*Yvs=7NA;e>EKCekgE+<6MX6r1*zIwvc)AmFn1gPd#Gv23v#aa045r@v=wr% z_auX$zZI5DLhLqcaUs<8Mafo35WOmkaj%QNEFB9l-CUQ)u&zNw)dv$83uq9)>4Dup xn(F@9T$P8DF`y-nEf?7lYUSx{_m8K$AHQsXuU_l$dy)VE002ovPDHLkV1lyBCtUyl literal 0 HcmV?d00001 diff --git a/src/Hamster.cpp b/src/Hamster.cpp index 7a06dc2..f26259a 100644 --- a/src/Hamster.cpp +++ b/src/Hamster.cpp @@ -150,11 +150,11 @@ void Hamster::DrawHamsters(TransformedView&tv){ const Animate2D::Frame&wheelBottomImg{wheelBottomAnim.GetFrame(h.distanceTravelled/80.f)}; if(h.state==FLYING)h.hamsterJet.value().Draw(); HamsterGame::Game().SetZ(h.z); - if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelBottomImg.GetSourceImage()->Decal(),h.rot,wheelBottomImg.GetSourceRect().size/2,wheelBottomImg.GetSourceRect().pos,wheelBottomImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); + if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos+vf2d{0.f,h.drawingOffsetY},wheelBottomImg.GetSourceImage()->Decal(),h.rot,wheelBottomImg.GetSourceRect().size/2,wheelBottomImg.GetSourceRect().pos,wheelBottomImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); HamsterGame::Game().SetZ(h.z+0.005f); - tv.DrawPartialRotatedDecal(h.pos,img.GetSourceImage()->Decal(),h.rot,img.GetSourceRect().size/2,img.GetSourceRect().pos,img.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); + tv.DrawPartialRotatedDecal(h.pos+vf2d{0.f,h.drawingOffsetY},img.GetSourceImage()->Decal(),h.rot,img.GetSourceRect().size/2,img.GetSourceRect().pos,img.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,WHITE,h.imgScale)); HamsterGame::Game().SetZ(h.z+0.01f); - if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos,wheelTopImg.GetSourceImage()->Decal(),h.rot,wheelTopImg.GetSourceRect().size/2,wheelTopImg.GetSourceRect().pos,wheelTopImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,{255,255,255,192},h.imgScale)); + if(h.HasPowerup(Powerup::WHEEL))tv.DrawPartialRotatedDecal(h.pos+vf2d{0.f,h.drawingOffsetY},wheelTopImg.GetSourceImage()->Decal(),h.rot,wheelTopImg.GetSourceRect().size/2,wheelTopImg.GetSourceRect().pos,wheelTopImg.GetSourceRect().size,vf2d{1.f,1.f}*h.imgScale,PixelLerp(h.shrinkEffectColor,{255,255,255,192},h.imgScale)); HamsterGame::Game().SetZ(0.f); } } @@ -261,6 +261,7 @@ const float Hamster::GetRadius()const{ } const Terrain::TerrainType Hamster::GetTerrainStandingOn()const{ + if(state==FLYING)return Terrain::ROCK; return HamsterGame::Game().GetTerrainTypeAtPos(GetPos()); } @@ -354,12 +355,12 @@ const float&Hamster::GetZ()const{ void Hamster::SetPos(const vf2d pos){ bool movedY{false}; - if(state==FLYING||!HamsterGame::Game().IsTerrainSolid(vf2d{this->pos.x,pos.y})){ + if(state==FLYING&&HamsterGame::Game().IsInBounds(vf2d{this->pos.x,pos.y})||!HamsterGame::Game().IsTerrainSolid(vf2d{this->pos.x,pos.y})){ this->pos=vf2d{this->pos.x,pos.y}; movedY=true; } - if(state==FLYING||!HamsterGame::Game().IsTerrainSolid(vf2d{pos.x,this->pos.y}))this->pos=vf2d{pos.x,this->pos.y}; - if (!movedY&&(state==FLYING||!HamsterGame::Game().IsTerrainSolid(vf2d{this->pos.x,pos.y})))this->pos=vf2d{this->pos.x,pos.y}; + if(state==FLYING&&HamsterGame::Game().IsInBounds(vf2d{pos.x,this->pos.y})||!HamsterGame::Game().IsTerrainSolid(vf2d{pos.x,this->pos.y}))this->pos=vf2d{pos.x,this->pos.y}; + if (!movedY&&(state==FLYING&&HamsterGame::Game().IsInBounds(vf2d{this->pos.x,pos.y})||!HamsterGame::Game().IsTerrainSolid(vf2d{this->pos.x,pos.y})))this->pos=vf2d{this->pos.x,pos.y}; } void Hamster::SetZ(const float z){ @@ -368,4 +369,8 @@ void Hamster::SetZ(const float z){ void Hamster::OnUserDestroy(){ HAMSTER_LIST.clear(); +} + +void Hamster::SetDrawingOffsetY(const float offsetY){ + drawingOffsetY=offsetY; } \ No newline at end of file diff --git a/src/Hamster.h b/src/Hamster.h index 998b026..d1bc77f 100644 --- a/src/Hamster.h +++ b/src/Hamster.h @@ -102,6 +102,7 @@ class Hamster{ std::unordered_setpowerups; std::optionalhamsterJet; float lastTappedSpace{0.f}; + float drawingOffsetY{0.f}; public: Hamster(const vf2d spawnPos,const std::string_view img,const PlayerControlled IsPlayerControlled=NPC); static const Hamster&GetPlayer(); @@ -134,4 +135,5 @@ public: void SetPos(const vf2d pos); void SetZ(const float z); static void OnUserDestroy(); + void SetDrawingOffsetY(const float offsetY); }; \ No newline at end of file diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index 1f24d1d..a609c5d 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -47,6 +47,7 @@ void HamsterGame::LoadGraphics(){ _LoadImage("hamster_jet.png"); _LoadImage("dot.png"); _LoadImage("clouds.png"); + _LoadImage("aimingTarget.png"); UpdateMatrixTexture(); } @@ -399,6 +400,10 @@ const float HamsterGame::GetZoom()const{ return zoom; } +const bool HamsterGame::IsInBounds(const vf2d pos)const{ + return !(pos.x<=-160.f||pos.y<=-160.f||pos.x>=currentMap.value().GetData().GetMapData().width*16+160.f||pos.y>=currentMap.value().GetData().GetMapData().height*16+160.f); +} + int main() { HamsterGame game; diff --git a/src/HamsterGame.h b/src/HamsterGame.h index f23906c..2f096fb 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -84,6 +84,7 @@ public: const bool IsTerrainSolid(const vf2d pos)const; void SetZoom(const float zoom); const float GetZoom()const; + const bool IsInBounds(const vf2d pos)const; private: void UpdateGame(const float fElapsedTime); void DrawGame(); diff --git a/src/HamsterJet.cpp b/src/HamsterJet.cpp index 1e86d57..fcf8d6c 100644 --- a/src/HamsterJet.cpp +++ b/src/HamsterJet.cpp @@ -49,6 +49,7 @@ void HamsterJet::Update(const float fElapsedTime){ jet.Update(fElapsedTime); lights.Update(fElapsedTime); timer=std::max(0.f,timer-fElapsedTime); + easeInTimer=std::max(0.f,easeInTimer-fElapsedTime); lastTappedSpace+=fElapsedTime; switch(state){ case SWOOP_DOWN:{ @@ -58,8 +59,7 @@ void HamsterJet::Update(const float fElapsedTime){ if(timer<=0.4f){ hamster.SetPos(hamsterOriginalPos-vf2d{0.f,sin(float(geom2d::pi)*timer/0.4f)*8.f}); hamster.SetZ(sin(float(geom2d::pi)*timer/0.4f)*0.2f); - jetState[TOP_LEFT]=OFF; - jetState[BOTTOM_LEFT]=OFF; + jetState[TOP_LEFT]=jetState[BOTTOM_LEFT]=jetState[BOTTOM_RIGHT]=jetState[TOP_RIGHT]=OFF; }else{ jetState[TOP_LEFT]=jetState[BOTTOM_LEFT]=jetState[BOTTOM_RIGHT]=jetState[TOP_RIGHT]=ON; pos=hamster.GetPos().lerp(originalPos,std::pow(timer/3.f,4)); @@ -81,7 +81,8 @@ void HamsterJet::Update(const float fElapsedTime){ hamster.SetZ(z+0.03f); if(timer<=0.f){ state=PLAYER_CONTROL; - HamsterGame::Game().SetZoom(1.f); + HamsterGame::Game().SetZoom(0.6f); + easeInTimer=0.6f; } }break; case PLAYER_CONTROL:{ @@ -92,19 +93,29 @@ void HamsterJet::Update(const float fElapsedTime){ } } void HamsterJet::Draw(){ + float drawingOffsetY{0.f}; + hamster.SetDrawingOffsetY(0.f); + if((state==PLAYER_CONTROL||state==LANDING)&&z>2.f){ + HamsterGame::Game().SetZ(z/2.f); + HamsterGame::Game().tv.DrawRotatedDecal(pos,HamsterGame::GetGFX("aimingTarget.png").Decal(),0.f,HamsterGame::GetGFX("aimingTarget.png").Sprite()->Size()/2); + } + if(state==PLAYER_CONTROL){ + drawingOffsetY=util::lerp(48.f,0.f,easeInTimer/0.6f); + hamster.SetDrawingOffsetY(util::lerp(48.f,0.f,easeInTimer/0.6f)); + } HamsterGame::Game().SetZ(z); - HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,jet.Decal(),0.f,{24,24},{},{48,48}); + HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},jet.Decal(),0.f,{24,24},{},{48,48}); const Animate2D::FrameSequence&flameAnim{HamsterGame::Game().GetAnimation("hamster_jet.png",HamsterGame::AnimationState::JET_FLAMES)}; const Animate2D::Frame&flameFrame{flameAnim.GetFrame(HamsterGame::Game().GetRuntime())}; HamsterGame::Game().SetZ(z+0.01f); - if(jetState[TOP_LEFT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,flameFrame.GetSourceImage()->Decal(),0.f,flameFrame.GetSourceRect().size/2,flameFrame.GetSourceRect().pos+vf2d{0,0},flameFrame.GetSourceRect().size/2); - if(jetState[BOTTOM_LEFT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,flameFrame.GetSourceImage()->Decal(),0.f,{24,0},flameFrame.GetSourceRect().pos+vf2d{0,24},flameFrame.GetSourceRect().size/2); - if(jetState[BOTTOM_RIGHT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,flameFrame.GetSourceImage()->Decal(),0.f,{0,0},flameFrame.GetSourceRect().pos+vf2d{24,24},flameFrame.GetSourceRect().size/2); - if(jetState[TOP_RIGHT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,flameFrame.GetSourceImage()->Decal(),0.f,{0,24},flameFrame.GetSourceRect().pos+vf2d{24,0},flameFrame.GetSourceRect().size/2); + if(jetState[TOP_LEFT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},flameFrame.GetSourceImage()->Decal(),0.f,flameFrame.GetSourceRect().size/2,flameFrame.GetSourceRect().pos+vf2d{0,0},flameFrame.GetSourceRect().size/2); + if(jetState[BOTTOM_LEFT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},flameFrame.GetSourceImage()->Decal(),0.f,{24,0},flameFrame.GetSourceRect().pos+vf2d{0,24},flameFrame.GetSourceRect().size/2); + if(jetState[BOTTOM_RIGHT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},flameFrame.GetSourceImage()->Decal(),0.f,{0,0},flameFrame.GetSourceRect().pos+vf2d{24,24},flameFrame.GetSourceRect().size/2); + if(jetState[TOP_RIGHT])HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},flameFrame.GetSourceImage()->Decal(),0.f,{0,24},flameFrame.GetSourceRect().pos+vf2d{24,0},flameFrame.GetSourceRect().size/2); const Animate2D::FrameSequence&lightAnim{HamsterGame::Game().GetAnimation("hamster_jet.png",HamsterGame::AnimationState::JET_LIGHTS)}; const Animate2D::Frame&lightFrame{lightAnim.GetFrame(HamsterGame::Game().GetRuntime())}; HamsterGame::Game().SetZ(z+0.02f); - HamsterGame::Game().tv.DrawPartialRotatedDecal(pos,lights.Decal(),0.f,lightFrame.GetSourceRect().size/2.f,lightFrame.GetSourceRect().pos,lightFrame.GetSourceRect().size); + HamsterGame::Game().tv.DrawPartialRotatedDecal(pos+vf2d{0,drawingOffsetY},lights.Decal(),0.f,lightFrame.GetSourceRect().size/2.f,lightFrame.GetSourceRect().pos,lightFrame.GetSourceRect().size); HamsterGame::Game().SetZ(0.f); } diff --git a/src/HamsterJet.h b/src/HamsterJet.h index bb09b5d..fb3bf3c 100644 --- a/src/HamsterJet.h +++ b/src/HamsterJet.h @@ -65,6 +65,7 @@ class HamsterJet{ vf2d hamsterOriginalPos; vf2d originalPos; vf2d targetPos; + float easeInTimer{}; float z; float targetZ{}; State state; diff --git a/src/TODO.txt b/src/TODO.txt index 882df3c..8999200 100644 --- a/src/TODO.txt +++ b/src/TODO.txt @@ -71,5 +71,26 @@ Fall-o-meter Hamster Rescue Boat + +LORE +=================== + +(?) discovered a strange floating energy orb while going for their morning run. Curious, they approached it and came into contact with it, granting them new powers. + +Excited by this discovery (?) decided to share it with the rest of their hamster friends. + +A couple villain/scientist hamsters realize that this has become a stubby legs race with great potential and recruited world class hamsters to run and obtain these new orbs for research. + + + + +Hamsters are experimenting with new technologies to emphasize their running capabilities beyond what was originally thought possible. + + + +Hamsters from all around Hamster planet have been recruited to scavenge for + +============================ + ============================ olcPGEX_ViewPort - Submit a PR where the offset is subtracted instead of added to determine clip region cutoffs. \ No newline at end of file