From c803df242ab4b06ad2a7f2718ce26ddc825ccc60 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Thu, 30 Oct 2025 22:46:20 +0000 Subject: [PATCH] fix(phase1.2b): apply buffered direction BEFORE movement, not after MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/useGameStatus/useGameStatus.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index 6aacd8c..083ef3c 100755 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -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);