Pygame/Python游戏未接收输入

2024-04-26 18:11:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在python上做一个游戏,我的问题是我不能让游戏在运行时读取输入。(连退出的退出键都没有)。 我找不到问题,我以为是缺少勾选方法,但我只是添加了它,它仍然不起作用。 感谢您的帮助。你知道吗

谢谢。你知道吗

代码如下: 立即编辑游戏循环

astronut=Player()
astronut.paintplayer()
while True:
    screen.fill(WHITE)
    for event in pygame.event.get():
        if event.type == QUIT:
            terminate()
        if event.type == KEYDOWN:
            if event.type == K_ESCAPE:
                terminate()
            if event.type == K_UP:
                astronut.acceleration +=1
                astronut.speed = astronut.speed + astronut.acceleration
                astronut.posY= astronut.posY + astronut.speed
            elif astronut.posY<(WINDOWHEIGHT-OVERTHELINE-playerHeight):
                astronut.acceleration -=1
                astronut.speed = astronut.speed + astronut.acceleration
                astronut.posY= astronut.posY + astronut.speed

    astronut.paintplayer()    
    pygame.display.update()
    mainClock.tick(FPS)

Tags: 方法代码event游戏编辑iftypepygame