Skip to content

Commit efb197c

Browse files
committed
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
1 parent d479f68 commit efb197c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/object/player.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,8 @@ Player::draw(DrawingContext& context)
22382238
const bool is_not_idle = std::all_of(IDLE_STAGES.begin(), IDLE_STAGES.end(),
22392239
[this](const std::string& stage) { return m_sprite->get_action().find("-" + stage + "-") == std::string::npos; });
22402240

2241+
std::string base_idle_action = sa_prefix + "-" + IDLE_STAGES[0] + sa_postfix;
2242+
22412243
if (is_not_idle || (m_should_fancy_idle && !m_fancy_idle_active) || m_reset_action)
22422244
{
22432245
m_idle_stage = 0;
@@ -2270,13 +2272,19 @@ Player::draw(DrawingContext& context)
22702272
else
22712273
set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, 1);
22722274
}
2275+
else if(m_sprite->get_action() != base_idle_action)
2276+
{
2277+
m_idle_stage = 0;
2278+
set_action(base_idle_action);
2279+
m_sprite->set_animation_loops(-1);
2280+
}
22732281
}
22742282
else
22752283
{
2276-
if (m_idle_stage != 0 || m_sprite->get_action() != sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix)
2284+
if (m_idle_stage != 0 || m_sprite->get_action() != base_idle_action)
22772285
{
22782286
m_idle_stage = 0;
2279-
set_action(sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix);
2287+
set_action(base_idle_action);
22802288
m_sprite->set_animation_loops(-1);
22812289
}
22822290
m_fancy_idle_active = false;

0 commit comments

Comments
 (0)