0
votes

I'm having a problem, that when I press the up arrow the bird doesn't go up. It seems like the game isn't detecting my keyboard inputs. The gravity function is working fine. Please help.

import pygame
import sys

pygame.init()

screen = pygame.display.set_mode((800, 600))

birdImg = pygame.image.load("bird.png")
birdImg = pygame.transform.scale(birdImg, (64, 64))
birdX = 300
birdY: int = 300
pipeImg = pygame.image.load("flappybirdpipe.png")
pipeImg = pygame.transform.scale(pipeImg, (100, 300))

def gravity():
    global birdY
    birdY += 3


background = pygame.image.load("flappybird.png")
background = pygame.transform.scale(background, (800, 600))

while True:
    screen.blit(background, (0, 0))
    screen.blit(birdImg, (birdX, birdY))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if pygame.event == pygame.KEYDOWN:
            if pygame.key == pygame.K_UP:
                birdY += -5
        if pygame.event == pygame.KEYUP:
            if pygame.key == pygame.K_UP:
                birdY = 0

    
    gravity()
    pygame.display.flip()
    pygame.display.update()
It,s a typo. if pygame.event must be if event.typeRabbid76