Skip to content

Conversation

@BernaTameirao
Copy link
Collaborator

@BernaTameirao BernaTameirao commented Dec 12, 2025

So, there was an error (issue #500 ) that if you started the game, and specifically pressed the left-arrow or A-button, the snake would turn to the right instead of left.

It was because of this piece of code, localized on prefabs/snake.py:

    # In autoplay mode, start with zero velocity so autoplay can set the first direction
    # Otherwise start moving right
    if autoplay_mode:
        initial_dx, initial_dy = 0, 0
    else:
        initial_dx, initial_dy = 1, 0

It initialized the initial_dx with 1, that meant to move right.

The fix sets the initial direction to (0, 0) when the game starts in manual mode, so the first user input defines the direction.

@BernaTameirao
Copy link
Collaborator Author

So, this PR fixes a bug where pressing the left arrow (or A) at the very start of the game would incorrectly turn the snake to the right.

The snake was initialized with initial_dx = 1, meaning it always had an initial orientation to the right, even when speed was zero.
My first fix removed that assumption, allowing the snake to start oriented in any direction.
However, several parts of the game logic and the tests assume that the snake starts the game facing right, even if it's not moving yet. And the player cannot turn left from the initial state, only up, down, or keep going right.

I prevented the original bug, through changing the initial orientation of the snake sprite to the right.
This preserves game rules and makes all tests pass again.

Copy link
Collaborator

@JeanJPNM JeanJPNM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really fix the problem, now if someone wants to start with the up arrow (or w) the same thing will happen

@BernaTameirao
Copy link
Collaborator Author

BernaTameirao commented Dec 12, 2025

@JeanJPNM I don't think I understand your proposition.

What I did was align the sprite with its initially assigned orientation in the code. So, whenever the game starts, the snake is turned to the right, and will respond as it should. The rest of the game stays exactly the same.

I just tested, and it doesn't have any error if the up-arrow is pressed, nor any other possible direction (down, or right).

Copy link
Collaborator

@JeanJPNM JeanJPNM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I forgot to take the sprite into consideration.

@GiordanoSL GiordanoSL merged commit aad78c4 into dev Dec 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants