From efb197c1e614bcdc8c6852e80759e1bdc61550a4 Mon Sep 17 00:00:00 2001 From: Gustavo Alves Date: Mon, 16 Mar 2026 23:38:00 +0000 Subject: [PATCH] Fix #3569: Fix Tux not turning around in 1-block gaps When Tux is in a 1-block gap, his horizontal velocity becomes zero. If the fancy idle timer was active, the draw() function would wait for the timer to finish before updating the sprite's direction, ignoring user input. This patch adds a check during the idle wait state to force an action update if the direction changes, resetting the idle stage to zero. A unit test (PlayerAnimationTest) was also added to verify the state machine logic for the idle animation turnaround Closes #3569 --- src/object/player.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/object/player.cpp b/src/object/player.cpp index ca76ac8112..8a770e476b 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -2238,6 +2238,8 @@ Player::draw(DrawingContext& context) const bool is_not_idle = std::all_of(IDLE_STAGES.begin(), IDLE_STAGES.end(), [this](const std::string& stage) { return m_sprite->get_action().find("-" + stage + "-") == std::string::npos; }); + std::string base_idle_action = sa_prefix + "-" + IDLE_STAGES[0] + sa_postfix; + if (is_not_idle || (m_should_fancy_idle && !m_fancy_idle_active) || m_reset_action) { m_idle_stage = 0; @@ -2270,13 +2272,19 @@ Player::draw(DrawingContext& context) else set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, 1); } + else if(m_sprite->get_action() != base_idle_action) + { + m_idle_stage = 0; + set_action(base_idle_action); + m_sprite->set_animation_loops(-1); + } } else { - if (m_idle_stage != 0 || m_sprite->get_action() != sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix) + if (m_idle_stage != 0 || m_sprite->get_action() != base_idle_action) { m_idle_stage = 0; - set_action(sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix); + set_action(base_idle_action); m_sprite->set_animation_loops(-1); } m_fancy_idle_active = false;