import pygame import sys import random pygame.init() screen = pygame.display.set_mode((1920, 1080)) pos = [960, 540] while True : events = pygame.event.get() for event in events : if event.type == pygame.QUIT : pygame.quit() sys.exit() if event.type == pygame.KEYDOWN : if event.key == pygame.K_RIGHT : surface = pygame.Surface((1000, 1000)) surface.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) pos[0] += 20 if event.key == pygame.K_LEFT : surface = pygame.Surface((1000, 1000)) surface.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) pos[0] -= 20 if event.key == pygame.K_UP : surface = pygame.Surface((1000, 1000)) surface.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) pos[1] -= 20 if event.key == pygame.K_DOWN : surface = pygame.Surface((1000, 1000)) surface.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) pos[1] += 20 screen.blit(surface, pos) pygame.display.update()