-
-
Notifications
You must be signed in to change notification settings - Fork 518
Let squished enemies fade out instead of vanishing instantly #3198
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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; | ||||||
|
@@ -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"); | ||||||
|
@@ -315,12 +317,22 @@ BadGuy::update(float dt_sec) | |||||
case STATE_SQUISHED: | ||||||
m_is_active_flag = false; | ||||||
if (m_state_timer.check()) { | ||||||
remove_me(); | ||||||
if (m_sprite->get_alpha() > 0.0f) { | ||||||
m_alpha_before_fadeout = m_sprite->get_alpha(); | ||||||
set_state(STATE_SQUISHED_FADING_OUT); | ||||||
} | ||||||
else | ||||||
remove_me(); | ||||||
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())); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here you'd only need to put m_state_timer.get_progress()
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If alpha was already lower than 1, the suggested change would put it up to 1 before fading out again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid point here. Although all badguys currently have alpha=1.0, it doesn't have to hold in future. If they already start at a lower value of alpha, then the suggested change won't work. Just for better readability, I would write it as:
|
||||||
break; | ||||||
case STATE_MELTING: { | ||||||
m_is_active_flag = false; | ||||||
m_col.set_movement(m_physic.get_movement(dt_sec)); | ||||||
|
@@ -760,6 +772,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 * m_sprite->get_alpha()); | ||||||
break; | ||||||
case STATE_GEAR: | ||||||
m_state_timer.start(GEAR_TIME); | ||||||
break; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure because I havent tested this in game but this might be too fast?? Someone else needs to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The effect is noticeable. I wouldn't mind if it was slower but this works too.