working on useGame

This commit is contained in:
2025-10-15 17:56:41 +01:00
parent da8ca2c289
commit 5b9b44aef6
2 changed files with 44 additions and 15 deletions
+12 -7
View File
@@ -35,16 +35,21 @@ export function useCursor(rendererManager: UseRenderer) {
if (animatingRef.current) return;
setCursor((prev) => {
let r = prev.r;
let c = prev.c;
for (let i = 0; i < steps; i++) {
r = Math.max(0, Math.min(8, r + dr));
c = Math.max(0, Math.min(8, c + dc));
const targetR = prev.r + (dr * steps);
const targetC = prev.c + (dc * steps);
// Check if the full counted move would go out of bounds
if (targetR < 0 || targetR > 8 || targetC < 0 || targetC > 8) {
// Flash invalid and don't move
setTimeout(() => flashInvalid(), 0);
return prev;
}
return { r, c };
// Valid move - apply it
return { r: targetR, c: targetC };
});
},
[]
[flashInvalid]
);
useEffect(() => {