首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何保持幽灵移动逻辑吃豆人

如何保持幽灵移动逻辑吃豆人
EN

Stack Overflow用户
提问于 2020-06-30 06:19:46
回答 1查看 30关注 0票数 0

我正在构建一个2D pacman克隆(javascript和CSS),并且我正在尝试移动一个幽灵/木乃伊。我写了moveGhostDown/Up/Left/Right。现在,它只是降低了一步。我尝试在while循环的moveGhost中包装if条件,但它导致应用程序崩溃。我如何让它保持移动,而不是瞬间跳跃?我也尝试过使用setTimeout,但它不起作用。

代码语言:javascript
复制
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;
    }
}
代码语言:javascript
复制
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();
    } 
}
EN

回答 1

Stack Overflow用户

发布于 2020-06-30 06:22:56

moveGhosrUp

看起来你打错了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62647512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档