Moved Hamster Jet camera down, added targeting indicator, fix ground detection issues while in the air.

main
sigonasr2 3 months ago
parent 121061f3b8
commit 8720d20b82
  1. BIN
      assets/aimingTarget.png
  2. 17
      src/Hamster.cpp
  3. 2
      src/Hamster.h
  4. 5
      src/HamsterGame.cpp
  5. 1
      src/HamsterGame.h
  6. 29
      src/HamsterJet.cpp
  7. 1
      src/HamsterJet.h
  8. 21
      src/TODO.txt

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -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;
}

@ -102,6 +102,7 @@ class Hamster{
std::unordered_set<Powerup::PowerupType>powerups;
std::optional<HamsterJet>hamsterJet;
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);
};

@ -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;

@ -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();

@ -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);
}

@ -65,6 +65,7 @@ class HamsterJet{
vf2d hamsterOriginalPos;
vf2d originalPos;
vf2d targetPos;
float easeInTimer{};
float z;
float targetZ{};
State state;

@ -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.
Loading…
Cancel
Save