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:
2025-10-30 22:46:20 +00:00
parent 4b0e386691
commit c803df242a
+3 -3
View File
@@ -66,6 +66,9 @@ export function useGameStatus(
const elapsed = timestamp - lastUpdateRef.current; const elapsed = timestamp - lastUpdateRef.current;
if (elapsed >= msPerFrame) { if (elapsed >= msPerFrame) {
// Apply any buffered direction input BEFORE moving
snakeManagerRef.current.applyBufferedDirection();
const result = snakeManagerRef.current.moveSnake(shouldGrow); const result = snakeManagerRef.current.moveSnake(shouldGrow);
shouldGrow = false; shouldGrow = false;
@@ -79,9 +82,6 @@ export function useGameStatus(
return; return;
} }
// Apply any buffered direction input for next frame
snakeManagerRef.current.applyBufferedDirection();
const head = snakeManagerRef.current.snakeBodyRef.current[0]; const head = snakeManagerRef.current.snakeBodyRef.current[0];
if (head && foodManagerRef.current.checkFoodCollision(head)) { if (head && foodManagerRef.current.checkFoodCollision(head)) {
foodManagerRef.current.removeFood(head); foodManagerRef.current.removeFood(head);