我正在构建一个2D pacman克隆(javascript和CSS),并且我正在尝试移动一个幽灵/木乃伊。我写了moveGhostDown/Up/Left/Right。现在,它只是降低了一步。我尝试在while循环的moveGhost中包装if条件,但它导致应用程序崩溃。我如何让它保持移动,而不是瞬间跳跃?我也尝试过使用setTimeout,但它不起作用。
function moveGhostDown() {
if ((grid[ghost.y + 1][ghost.x] !== STONE) && (grid[ghost.y + 1][ghost.x] !== KEY)) {
let last = grid[ghost.y + 1][ghost.x];
grid[ghost.y][ghost.x] = last;
ghost.y = ghost.y + 1;
grid[ghost.y][ghost.x] = MUMMY;
}
}function moveGhost() {
if ((pacman.x > ghost.x) && (pacman.y > ghost.y)) {
moveGhostDown();
// moveGhostRight();
// moveLeft();
} else if ((pacman.x >= ghost.x) && (pacman.y <= ghost.y)) {
moveGhosrUp();
} else if ((pacman.x < ghost.x) && (pacman.y < ghost.y)) {
moveGhostRight();
// moveGhostLeft();
}
}发布于 2020-06-30 06:22:56
moveGhosrUp
看起来你打错了
https://stackoverflow.com/questions/62647512
复制相似问题