From 4b0e38669128b4253214d84f2eefc5b13b0bfc90 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Thu, 30 Oct 2025 22:41:52 +0000 Subject: [PATCH] =?UTF-8?q?fix(phase1.2b):=20adjust=20key=20buffer=20logic?= =?UTF-8?q?=20to=20allow=20180=C2=B0=20reversals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change buffer validation from lastMovedDirection to currentDirection - This allows 180° reversals across frames (they're safe if you have space) - Only blocks immediate 180° within same frame (would cause self-collision) - Removes overly restrictive direction blocking - Player can now freely turn in any direction between moves - Should fix the 'impossible to turn' and 'immediate death' issues --- src/useCursor/useCursor.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/useCursor/useCursor.ts b/src/useCursor/useCursor.ts index 95a3139..d18648a 100755 --- a/src/useCursor/useCursor.ts +++ b/src/useCursor/useCursor.ts @@ -97,18 +97,8 @@ export function useCursor( }; const changeDirection = (newDirection: Direction) => { - const opposites: Record = { - up: "down", - down: "up", - left: "right", - right: "left", - }; - - // Buffer the direction instead of applying immediately - // Only buffer if it's not a 180° reversal of the last MOVED direction - if (opposites[lastMovedDirectionRef.current] !== newDirection) { - nextDirectionRef.current = newDirection; - } + // Simply buffer the direction - apply validation on next move + nextDirectionRef.current = newDirection; }; const applyBufferedDirection = () => { @@ -122,8 +112,9 @@ export function useCursor( right: "left", }; - // Apply buffer only if still valid (not 180° reversal) - if (opposites[lastMovedDirectionRef.current] !== newDirection) { + // Only prevent immediate 180° reversal (would cause self-collision on same frame) + // This is the CURRENT direction, not the last moved direction + if (opposites[directionRef.current] !== newDirection) { setDirection(newDirection); directionRef.current = newDirection; nextDirectionRef.current = null;