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);