fix(phase1.2b): adjust key buffer logic to allow 180° reversals
- 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
This commit is contained in:
@@ -97,18 +97,8 @@ export function useCursor(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const changeDirection = (newDirection: Direction) => {
|
const changeDirection = (newDirection: Direction) => {
|
||||||
const opposites: Record<Direction, Direction> = {
|
// Simply buffer the direction - apply validation on next move
|
||||||
up: "down",
|
nextDirectionRef.current = newDirection;
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const applyBufferedDirection = () => {
|
const applyBufferedDirection = () => {
|
||||||
@@ -122,8 +112,9 @@ export function useCursor(
|
|||||||
right: "left",
|
right: "left",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply buffer only if still valid (not 180° reversal)
|
// Only prevent immediate 180° reversal (would cause self-collision on same frame)
|
||||||
if (opposites[lastMovedDirectionRef.current] !== newDirection) {
|
// This is the CURRENT direction, not the last moved direction
|
||||||
|
if (opposites[directionRef.current] !== newDirection) {
|
||||||
setDirection(newDirection);
|
setDirection(newDirection);
|
||||||
directionRef.current = newDirection;
|
directionRef.current = newDirection;
|
||||||
nextDirectionRef.current = null;
|
nextDirectionRef.current = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user