Skip to content

Commit

Permalink
Finish growing animation before turn to stone (#2810)
Browse files Browse the repository at this point in the history
- Wait until the growing animation is finished before changing to stone animation when smallTux gains an earth flower.
- Fix animation glitch from sliding to slidegrow
- Remain in crawling action when down is held and Tux stops sliding due to friction

Fixes #2533
  • Loading branch information
Brockengespenst authored Aug 31, 2024
1 parent d0b492a commit c0be88d
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ Player::update(float dt_sec)
adjust_height(BIG_TUX_HEIGHT, 10.f);
do_duck();
}
else if (!is_big() || m_stone)
else if (!is_big() || (m_stone && !m_growing))
{
adjust_height(SMALL_TUX_HEIGHT);
}
Expand Down Expand Up @@ -602,8 +602,8 @@ Player::update(float dt_sec)

//End of wallclinging

// Roll the sprite if Tux is rolling
if (m_stone)
// Roll the sprite if Tux is rolling (and not growing)
if (m_stone && !m_growing)
{
float f = 1.f;

Expand Down Expand Up @@ -723,7 +723,8 @@ Player::update(float dt_sec)
}

if (m_growing) {
if (m_sprite->animation_done()) m_growing = false;
if (m_sprite->animation_done())
m_growing = false;
}

// when climbing animate only while moving
Expand Down Expand Up @@ -805,19 +806,19 @@ Player::update(float dt_sec)

//if you stop holding down when sliding, then it stops.
//or, stop sliding if you come to a stop and are not on a slope.
if (!m_controller->hold(Control::DOWN) ||
(m_floor_normal.y == 0.f && std::abs(m_physic.get_velocity_x()) <= 1.f))
if (!m_controller->hold(Control::DOWN))
{
if (is_big())
{
if (m_controller->hold(Control::LEFT) || m_controller->hold(Control::RIGHT)) {
m_sliding = false;
m_slidejumping = false;

do_standup(false);
}
else if (m_floor_normal.y == 0.f && std::abs(m_physic.get_velocity_x()) <= 1.f)
{
if (is_big() || m_growing)
m_crawl = true;
}
m_duck = true;
}
m_sliding = false;
m_slidejumping = false;
m_was_crawling_before_slide = false;
}
}

Expand Down Expand Up @@ -1583,7 +1584,7 @@ Player::handle_input()
}

/* Turn to Stone */
if (m_controller->hold(Control::DOWN) && !m_does_buttjump && m_coyote_timer.started() && !m_swimming && (std::abs(m_physic.get_velocity_x()) > 150.f) && get_bonus() == EARTH_BONUS) {
if (m_controller->hold(Control::DOWN) && !m_does_buttjump && m_coyote_timer.started() && !m_swimming && (std::abs(m_physic.get_velocity_x()) > 150.f) && get_bonus() == EARTH_BONUS && !m_growing) {
m_physic.set_gravity_modifier(1.0f); // Undo jump_early_apex
adjust_height(TUX_WIDTH);
m_stone = true;
Expand All @@ -1598,11 +1599,11 @@ Player::handle_input()
apply_friction();

/* Duck or Standup! */
if ((m_controller->pressed(Control::DOWN) || ((m_duck || m_wants_buttjump) && m_controller->hold(Control::DOWN))) &&
!m_swimming && !m_sliding && !m_stone) {
if (((m_controller->pressed(Control::DOWN) && !m_growing && !m_stone) || ((m_duck || m_wants_buttjump || m_crawl) && m_controller->hold(Control::DOWN))) &&
!m_swimming && !m_sliding && !m_stone && !m_growing) {
do_duck();
}
else {
else if (!m_sliding && !m_growing) {
do_standup(false);
}

Expand Down Expand Up @@ -1902,7 +1903,7 @@ Player::set_bonus(BonusType type, bool animate, bool increment_powerup_counter)
}

if ((get_bonus() == NO_BONUS) && (type != NO_BONUS || m_stone)) {
if (!m_swimming)
if (!m_swimming && !m_sliding)
{
if (!adjust_height(BIG_TUX_HEIGHT))
{
Expand Down Expand Up @@ -2088,15 +2089,16 @@ Player::draw(DrawingContext& context)
m_sprite->set_action(sa_prefix +"-slidejump"+ sa_postfix);
}
else {
const bool was_growing_before = (m_sprite->get_action().substr(0, 9) == "slidegrow");
m_sprite->set_action(sa_prefix + "-slide" + sa_postfix);
if (m_was_crawling_before_slide)
if (m_was_crawling_before_slide || was_growing_before)
{
m_sprite->set_frame(m_sprite->get_frames()); // Skip the "duck" animation when coming from crawling
m_sprite->set_frame(m_sprite->get_frames()); // Skip the "duck" animation when coming from crawling or slidegrowing
m_was_crawling_before_slide = false;
}
}
}
else if (m_duck && is_big() && !m_swimming && !m_crawl) {
else if (m_duck && is_big() && !m_swimming && !m_crawl && !m_stone) {
m_sprite->set_action(sa_prefix+"-duck"+sa_postfix);
}
else if (m_crawl)
Expand Down

0 comments on commit c0be88d

Please sign in to comment.