Java-Snake-Game icon indicating copy to clipboard operation
Java-Snake-Game copied to clipboard

Diagonal / inconsistent movement when multiple direction flags are true

Open Zsozsiii opened this issue 1 month ago • 0 comments

If more than one direction flag (leftDirection, rightDirection, upDirection, downDirection) is true at the same time, the snake movement becomes inconsistent and can effectively behave like a diagonal move. Under fast consecutive key presses, more than one direction flag can end up being true. In those cases, the move() method applies multiple updates in a single tick, which causes the head to move in an unexpected direction (a combination of the active flags), instead of following only the last valid direction. At any given game tick exactly one direction should be active, and the snake should move only in that single direction (the last valid direction pressed by the player). Multiple direction flags being true simultaneously should never result in a combined or diagonal movement.

Zsozsiii avatar Dec 06 '25 13:12 Zsozsiii