Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let squished enemies fade out instead of vanishing instantly #3198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
static const float SQUISH_TIME = 2;
static const float GEAR_TIME = 2;
static const float BURN_TIME = 1;
static const float FADEOUT_TIME = 0.2f;

static const float X_OFFSCREEN_DISTANCE = 1280;
static const float Y_OFFSCREEN_DISTANCE = 800;
Expand Down Expand Up @@ -77,7 +78,8 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite
m_is_active_flag(),
m_state_timer(),
m_on_ground_flag(false),
m_colgroup_active(COLGROUP_MOVING)
m_colgroup_active(COLGROUP_MOVING),
m_alpha_before_fadeout(1.0f)
{
SoundManager::current()->preload("sounds/squish.wav");
SoundManager::current()->preload("sounds/fall.wav");
Expand Down Expand Up @@ -315,12 +317,18 @@ BadGuy::update(float dt_sec)
case STATE_SQUISHED:
m_is_active_flag = false;
if (m_state_timer.check()) {
remove_me();
m_alpha_before_fadeout = m_sprite->get_alpha();
set_state(STATE_SQUISHED_FADING_OUT);
break;
}
m_col.set_movement(m_physic.get_movement(dt_sec));
break;

case STATE_SQUISHED_FADING_OUT:
if (m_state_timer.check())
remove_me();
else
m_sprite->set_alpha(m_alpha_before_fadeout - (m_alpha_before_fadeout * m_state_timer.get_progress()));
break;
case STATE_MELTING: {
m_is_active_flag = false;
m_col.set_movement(m_physic.get_movement(dt_sec));
Expand Down Expand Up @@ -760,6 +768,9 @@ BadGuy::set_state(State state_)
case STATE_SQUISHED:
m_state_timer.start(SQUISH_TIME);
break;
case STATE_SQUISHED_FADING_OUT:
m_state_timer.start(FADEOUT_TIME);
break;
case STATE_GEAR:
m_state_timer.start(GEAR_TIME);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class BadGuy : public MovingSprite,
STATE_INACTIVE,
STATE_ACTIVE,
STATE_SQUISHED,
STATE_SQUISHED_FADING_OUT,
STATE_FALLING,
STATE_BURNING,
STATE_MELTING,
Expand Down Expand Up @@ -322,6 +323,9 @@ class BadGuy : public MovingSprite,
/** CollisionGroup the badguy should be in while active */
CollisionGroup m_colgroup_active;

/** The alpha value at the time the Badguy begins to fadeout */
float m_alpha_before_fadeout;

private:
BadGuy(const BadGuy&) = delete;
BadGuy& operator=(const BadGuy&) = delete;
Expand Down
Loading