I am building a game but I can't move left. Help.
I am building a game using python with pygame. I spent a lot of time looking through the code but can't find the error. when I run the code the block moves right but not left!!! Can someone please tell me what I did wrong? Here is the code: import pygame import sys pygame.init() WIDTH = 800 HEIGHT = 600 RED = (255, 0, 0) player_pos = [400, 300] player_size = 50 screen = pygame.display.set_mode((WIDTH, HEIGHT)) game_over = False while not game_over: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: x = player_pos[0] y = player_pos[1] if event.key == pygame.K_LEFT: x -= player_size elif event.key == pygame.K_RIGHT: x += player_size player_pos = [x,y] screen.fill((0,0,0)) pygame.draw.rect(screen, RED, (player_pos[0], player_pos[1], player_size, player_size)) pygame.display. update()