角色移动问题

时间:2019-07-07 23:17:28

标签: python python-3.x pygame pycharm

我更改了敌人的路径,但是在1次尝试后游戏显示变黑,然后我将敌人的路径恢复为正常,但随后我的角色无法移动... pygame或pycharm

我试图多次按“ Ctrl + z”,但是它也没有起作用。

我的移动代码:

        if keys[pygame.K_LEFT] and man.x > man.vel:
        man.x -= man.vel
        man.left = True
        man.right = False
        man.standing = False
    elif keys[pygame.K_RIGHT] and man.x < 500 - man.width - man.vel:
        man.x += man.vel
        man.right = True
        man.left = False
        man.standing = False
    else:
        man.standing = True
        man.walkCount = 0

    if not (man.isJump):
        if keys[pygame.K_UP]:
            man.isJump = True
            man.right = False
            man.left = False
            man.walkCount = 0
    else:
        if man.jumpCount >= -10:
            neg = 1
            if man.jumpCount < 0:
                neg = -1
            man.y -= (man.jumpCount ** 2) * 0.5 * neg
            man.jumpCount -= 1
        else:
            man.isJump = False
            man.jumpCount = 10
        man.jumpCount = 10

完整的代码,您可以在这里看到:

主要:https://pastebin.com/pHgtUi5F

玩家:https://pastebin.com/C4kmU2Rn

投射物:https://pastebin.com/LgG5kCu3

敌人:https://pastebin.com/wsgcbtUG

1 个答案:

答案 0 :(得分:0)

好了,它开始起作用了...因此,我在主循环中添加了keys = pygame.key.get_pressed(),然后从{{删除了if K_LEFTif K_RIGHT等... 1}},所以我的步行代码如下:

if K_SPACE