I am working on a christmas pygame game and I'm trying to have a bag move and keep moving when I press the left or right arrow keys. There is no error but when I press the keys nothing happens. Any idea what I'm doing wrong? Heres the code thanks!:
import pygame
import sys
width = 1024
height = 768
left = (-1, 0)
right = (1, 0)
sprite1 = pygame.image.load("Firstpygamegame/santabag2.png")
icon1 = pygame.image.load("Firstpygamegame/santa-claus.png")
pygame.display.set_icon(icon1)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Gift Catcher")
background_image = pygame.image.load("Firstpygamegame/wintervillage.png")
running = True
while running:
screen.blit(background_image, (0, 0))
screen.blit(sprite1, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if pygame.key == pygame.K_RIGHT:
rect = sprite1.get_rect()
rect = rect.move((1, 0))
screen.blit(sprite1, rect)
elif pygame.key == pygame.K_LEFT:
rect = sprite1.get_rect()
rect = rect.move((-1, 0))
screen.blit(sprite1, rect)
pygame.display.flip()