Skip to content

Commit

Permalink
Finish growing animation before turn to stone
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
  • Loading branch information
Brockengespenst committed Mar 1, 2024
1 parent 2e08c1b commit f1124c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
m_target_sliding_angle(0.0f),
m_sliding_rotation_timer(),
m_is_slidejump_falling(false),
m_was_crawling_before_slide(false)
m_was_crawling_before_slide(false),
m_slidegrowing(false)
{
m_name = name_;
m_idle_timer.start(static_cast<float>(TIME_UNTIL_IDLE) / 1000.0f);
Expand Down Expand Up @@ -468,7 +469,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 @@ -590,8 +591,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 @@ -711,7 +712,11 @@ Player::update(float dt_sec)
}

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

// when climbing animate only while moving
Expand Down Expand Up @@ -1573,7 +1578,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 @@ -1588,11 +1593,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_controller->hold(Control::DOWN))) &&
!m_swimming && !m_sliding && !m_stone && !m_growing && !m_slidegrowing) {
do_duck();
}
else {
else if (!m_slidegrowing) {
do_standup(false);
}

Expand Down Expand Up @@ -1885,7 +1890,7 @@ Player::set_bonus(BonusType type, bool animate)
}

if ((get_bonus() == NO_BONUS) && (type != NO_BONUS || m_stone)) {
if (!m_swimming)
if (!m_swimming && !m_sliding && !m_slidegrowing)
{
if (!adjust_height(BIG_TUX_HEIGHT))
{
Expand All @@ -1900,7 +1905,10 @@ Player::set_bonus(BonusType type, bool animate)
else if (m_swimming)
m_sprite->set_action("swimgrow", m_dir, 1);
else if (m_sliding)
{
m_sprite->set_action("slidegrow", m_dir, 1);
m_slidegrowing = true;
}
else
m_sprite->set_action("grow", m_dir , 1);
}
Expand Down Expand Up @@ -2041,7 +2049,7 @@ Player::draw(DrawingContext& context)
if (m_swimming || m_water_jump) {
action = "swimgrow";
}
else if (m_sliding) {
else if (m_sliding || m_slidegrowing) {
action = "slidegrow";
}
else if (m_climbing) {
Expand All @@ -2068,14 +2076,14 @@ Player::draw(DrawingContext& context)
}
else {
m_sprite->set_action(sa_prefix + "-slide" + sa_postfix);
if (m_was_crawling_before_slide)
if (m_was_crawling_before_slide || m_slidegrowing)
{
m_sprite->set_frame(m_sprite->get_frames()); // Skip the "duck" animation when coming from crawling
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
1 change: 1 addition & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class Player final : public MovingObject,
Timer m_sliding_rotation_timer;
bool m_is_slidejump_falling;
bool m_was_crawling_before_slide;
bool m_slidegrowing;

private:
Player(const Player&) = delete;
Expand Down

0 comments on commit f1124c5

Please sign in to comment.