From 023c6f900584585286556a3873d1b1f632e770b5 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 13 Aug 2023 23:01:23 -0500 Subject: [PATCH] Implement Z axis for monster rendering. Fix up shadow sizing for the player. --- Crawler/Bullet.h | 4 ++-- Crawler/Crawler.cpp | 24 ++++++++++++++---------- Crawler/Monster.cpp | 12 ++++++++++-- Crawler/Monster.h | 1 + Crawler/Version.h | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Crawler/Bullet.h b/Crawler/Bullet.h index 9d78dd10..fe58dc5d 100644 --- a/Crawler/Bullet.h +++ b/Crawler/Bullet.h @@ -35,9 +35,9 @@ public: Bullet(vf2d pos,vf2d vel,float radius,int damage,std::string animation,bool upperLevel,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,bool friendly=false,Pixel col=WHITE,vf2d scale={1,1}); public: virtual void Update(float fElapsedTime); - //Return true when the bullet should be destroyed. Return false to handle it otherwise (like deactivating it instead). You become responsible for getting rid of the bullet. + //Used by special bullets to control custom despawning behavior! Return true when the bullet should be destroyed. Return false to handle it otherwise (like deactivating it instead). You become responsible for getting rid of the bullet. virtual bool PlayerHit(Player*player); - //Return true when the bullet should be destroyed. Return false to handle it otherwise (like deactivating it instead). You become responsible for getting rid of the bullet. + //Used by special bullets to control custom despawning behavior! Return true when the bullet should be destroyed. Return false to handle it otherwise (like deactivating it instead). You become responsible for getting rid of the bullet. virtual bool MonsterHit(Monster&monster); Animate2D::Frame GetFrame(); virtual void Draw(); diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index a06eecf7..20bffd37 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -448,11 +448,13 @@ void Crawler::UpdateBullets(float fElapsedTime){ if(geom2d::overlaps(geom2d::circle(m.GetPos(),12*m.GetSizeMult()),geom2d::circle(b->pos,b->radius))){ if(b->hitList.find(&m)==b->hitList.end()&&m.Hurt(b->damage,b->OnUpperLevel())){ if(!b->hitsMultiple){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - goto outsideBulletLoop; + if(b->MonsterHit(m)){ + it=BULLET_LIST.erase(it); + if(it==BULLET_LIST.end()){ + goto outsideBulletLoop; + } + goto continueBulletLoop; } - goto continueBulletLoop; } b->hitList[&m]=true; } @@ -461,11 +463,13 @@ void Crawler::UpdateBullets(float fElapsedTime){ } else { if(geom2d::overlaps(geom2d::circle(player->GetPos(),12*player->GetSizeMult()/2),geom2d::circle(b->pos,b->radius))){ if(player->Hurt(b->damage,b->OnUpperLevel())){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - goto outsideBulletLoop; + if(b->PlayerHit(player.get())){ + it=BULLET_LIST.erase(it); + if(it==BULLET_LIST.end()){ + goto outsideBulletLoop; + } + goto continueBulletLoop; } - goto continueBulletLoop; } } } @@ -611,8 +615,8 @@ void Crawler::RenderWorld(float fElapsedTime){ PopulateRenderLists(monstersBeforeLower,monstersBeforeUpper,monstersAfterLower,monstersAfterUpper,bulletsLower,bulletsUpper,backgroundEffectsLower,backgroundEffectsUpper,foregroundEffectsLower,foregroundEffectsUpper); if(player->GetZ()>0){ - vf2d shadowScale=vf2d{8/3.f,1}/std::max(1.f,player->GetZ()/4); - view.DrawDecal(player->GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6},GFX_Circle.Decal(),shadowScale,BLACK); + vf2d shadowScale=vf2d{8*player->GetSizeMult()/3.f,1}/std::max(1.f,player->GetZ()/24); + view.DrawDecal(player->GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6*player->GetSizeMult()},GFX_Circle.Decal(),shadowScale,BLACK); } for(Effect*e:backgroundEffectsLower){ e->Draw(); diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 20e6418f..3effb18c 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -174,10 +174,14 @@ Key Monster::GetFacingDirection(){ return facingDirection; } void Monster::Draw(){ + if(GetZ()>0){ + vf2d shadowScale=vf2d{8*GetSizeMult()/3.f,1}/std::max(1.f,GetZ()/24); + game->view.DrawDecal(GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6*GetSizeMult()},game->GFX_Circle.Decal(),shadowScale,BLACK); + } if(GetFacingDirection()==RIGHT){ - game->view.DrawPartialDecal((GetPos()+vf2d{float(GetFrame().GetSourceRect().size.x),0}*GetSizeMult())-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*-1,GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); + game->view.DrawPartialDecal((GetPos()+vf2d{float(GetFrame().GetSourceRect().size.x),0}*GetSizeMult())-vf2d{12,12}*GetSizeMult()-vf2d{0,GetZ()},GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*-1,GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); } else { - game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); + game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult()-vf2d{0,GetZ()},GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); } } void Monster::Collision(Player*p){ @@ -345,4 +349,8 @@ void Monster::InitializeStrategies(){ bool Monster::HasIframes(){ return iframe_timer>0; +} + +float Monster::GetZ(){ + return z; } \ No newline at end of file diff --git a/Crawler/Monster.h b/Crawler/Monster.h index 9ad37c39..dd162474 100644 --- a/Crawler/Monster.h +++ b/Crawler/Monster.h @@ -126,6 +126,7 @@ public: void SetState(State newState); static void InitializeStrategies(); bool HasIframes(); + float GetZ(); private: struct STRATEGY{ static int _GetInt(Monster&m,std::string param,int strategyNumber,int index=0); diff --git a/Crawler/Version.h b/Crawler/Version.h index 15a447f4..f897d8b6 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1011 +#define VERSION_BUILD 1020 #define stringify(a) stringify_(a) #define stringify_(a) #a