fix(phase1.2b): apply buffered direction BEFORE movement, not after
- Move applyBufferedDirection() to execute before moveSnake() - This ensures buffered input is used for the current frame's movement - Allows multi-frame 180° turns (down then left, for example) - Snake can turn in any valid direction across frames - Fixes the 180° reversal restriction issue
This commit is contained in:
@@ -66,6 +66,9 @@ export function useGameStatus(
|
||||
const elapsed = timestamp - lastUpdateRef.current;
|
||||
|
||||
if (elapsed >= msPerFrame) {
|
||||
// Apply any buffered direction input BEFORE moving
|
||||
snakeManagerRef.current.applyBufferedDirection();
|
||||
|
||||
const result = snakeManagerRef.current.moveSnake(shouldGrow);
|
||||
|
||||
shouldGrow = false;
|
||||
@@ -79,9 +82,6 @@ export function useGameStatus(
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply any buffered direction input for next frame
|
||||
snakeManagerRef.current.applyBufferedDirection();
|
||||
|
||||
const head = snakeManagerRef.current.snakeBodyRef.current[0];
|
||||
if (head && foodManagerRef.current.checkFoodCollision(head)) {
|
||||
foodManagerRef.current.removeFood(head);
|
||||
|
||||
Reference in New Issue
Block a user