The_cuke_of_cukes
The_cuke_of_cukes

Reputation: 5

Pygame/Python game not receiving inputs

I'm trying to make a game on python, my problem is that I can't get the game to read inputs while running. (Not even the Escape key to exit). I can't find the problem, I thought it was the lack of the tick method but I just added it and it still doesn't work. Any help is appreciated.

Thanks.

Here's the code: Edit Now just the game loop

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)

Upvotes: 0

Views: 173

Answers (1)

Robb
Robb

Reputation: 433

I think you need to check the event.key instead of event.type:

    if event.type == KEYDOWN:
        if event.key == K_ESCAPE:
            terminate()
        ...

Upvotes: 1

Related Questions