From 6e4c7e603bcb3354dfd287799b7cb59b93b8431f Mon Sep 17 00:00:00 2001 From: "daniel.nunessilva" Date: Thu, 30 Oct 2025 15:02:03 -0300 Subject: [PATCH] =?UTF-8?q?evitando=20mexer=20a=20barra=20de=20scroll=20co?= =?UTF-8?q?m=20a=20seta=20e=20adicionando=20navega=C3=A7=C3=A3o=20do=20pac?= =?UTF-8?q?=20man=20com=20WASD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/games/pacman/Game.tsx | 63 ++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/app/games/pacman/Game.tsx b/app/games/pacman/Game.tsx index 589518c..5143b35 100644 --- a/app/games/pacman/Game.tsx +++ b/app/games/pacman/Game.tsx @@ -11,18 +11,6 @@ import { FRIGHTENED_MS, } from "./constants"; import { - MAP, - ROWS, - COLS, - replaceMapChar, - resetMapToOriginal, - autoFillPellets, -} from "./map"; -import { - isWall, - isPellet, - isPower, - nextCell, manhattan, choice, cellCenter, @@ -30,7 +18,19 @@ import { validDirs, canTurn, chooseClosest, + isWall, + isPellet, + isPower, + nextCell, } from "./logic"; +import { + MAP, + ROWS, + COLS, + replaceMapChar, + resetMapToOriginal, + autoFillPellets, +} from "./map"; import { drawMap, drawPacman, drawGhost, overlay } from "./render"; import { initGhostBrain, @@ -98,11 +98,40 @@ export default function Game() { setRunning((v) => !v); return; } - if (iaModeRef.current) return; // ignora setas em modo IA - if (e.key === "ArrowLeft") s.pacman.nextDir = "left"; - else if (e.key === "ArrowRight") s.pacman.nextDir = "right"; - else if (e.key === "ArrowUp") s.pacman.nextDir = "up"; - else if (e.key === "ArrowDown") s.pacman.nextDir = "down"; + if (iaModeRef.current) return; // ignora setas/WASD em modo IA + const isMoveKey = [ + "ArrowLeft", + "ArrowRight", + "ArrowUp", + "ArrowDown", + "a", + "A", + "d", + "D", + "w", + "W", + "s", + "S", + ].includes(e.key); + if (isMoveKey) { + e.preventDefault(); // evita scroll ou foco indesejado + if (e.key === "ArrowLeft" || e.key === "a" || e.key === "A") + s.pacman.nextDir = "left"; + else if ( + e.key === "ArrowRight" || + e.key === "d" || + e.key === "D" + ) + s.pacman.nextDir = "right"; + else if (e.key === "ArrowUp" || e.key === "w" || e.key === "W") + s.pacman.nextDir = "up"; + else if ( + e.key === "ArrowDown" || + e.key === "s" || + e.key === "S" + ) + s.pacman.nextDir = "down"; + } }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey);