Skip to content

Commit 40ce435

Browse files
Let squished enemies fade out instead of vanishing instantly
Squished enemies will now fadeout instead of vanishing instantly. This looks a bit smoother and is more aligned with the melting or burning animation.
1 parent 53af7b2 commit 40ce435

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/badguy/badguy.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
static const float SQUISH_TIME = 2;
4343
static const float GEAR_TIME = 2;
4444
static const float BURN_TIME = 1;
45+
static const float FADEOUT_TIME = 0.2f;
4546

4647
static const float X_OFFSCREEN_DISTANCE = 1280;
4748
static const float Y_OFFSCREEN_DISTANCE = 800;
@@ -77,7 +78,8 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite
7778
m_is_active_flag(),
7879
m_state_timer(),
7980
m_on_ground_flag(false),
80-
m_colgroup_active(COLGROUP_MOVING)
81+
m_colgroup_active(COLGROUP_MOVING),
82+
m_alpha_before_fadeout(1.0f)
8183
{
8284
SoundManager::current()->preload("sounds/squish.wav");
8385
SoundManager::current()->preload("sounds/fall.wav");
@@ -315,12 +317,18 @@ BadGuy::update(float dt_sec)
315317
case STATE_SQUISHED:
316318
m_is_active_flag = false;
317319
if (m_state_timer.check()) {
318-
remove_me();
320+
m_alpha_before_fadeout = m_sprite->get_alpha();
321+
set_state(STATE_SQUISHED_FADING_OUT);
319322
break;
320323
}
321324
m_col.set_movement(m_physic.get_movement(dt_sec));
322325
break;
323-
326+
case STATE_SQUISHED_FADING_OUT:
327+
if (m_state_timer.check())
328+
remove_me();
329+
else
330+
m_sprite->set_alpha(m_alpha_before_fadeout - (m_alpha_before_fadeout * m_state_timer.get_progress()));
331+
break;
324332
case STATE_MELTING: {
325333
m_is_active_flag = false;
326334
m_col.set_movement(m_physic.get_movement(dt_sec));
@@ -760,6 +768,9 @@ BadGuy::set_state(State state_)
760768
case STATE_SQUISHED:
761769
m_state_timer.start(SQUISH_TIME);
762770
break;
771+
case STATE_SQUISHED_FADING_OUT:
772+
m_state_timer.start(FADEOUT_TIME);
773+
break;
763774
case STATE_GEAR:
764775
m_state_timer.start(GEAR_TIME);
765776
break;

src/badguy/badguy.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class BadGuy : public MovingSprite,
165165
STATE_INACTIVE,
166166
STATE_ACTIVE,
167167
STATE_SQUISHED,
168+
STATE_SQUISHED_FADING_OUT,
168169
STATE_FALLING,
169170
STATE_BURNING,
170171
STATE_MELTING,
@@ -322,6 +323,9 @@ class BadGuy : public MovingSprite,
322323
/** CollisionGroup the badguy should be in while active */
323324
CollisionGroup m_colgroup_active;
324325

326+
/** The alpha value at the time the Badguy begins to fadeout */
327+
float m_alpha_before_fadeout;
328+
325329
private:
326330
BadGuy(const BadGuy&) = delete;
327331
BadGuy& operator=(const BadGuy&) = delete;

0 commit comments

Comments
 (0)