import pygame from pygame.locals import * import sys pygame.init() screen = pygame.display.set_mode((1000,1000)) background = pygame.Surface((400, 400)) width = 20 height = 20 surface = pygame.Surface((width, height)) surface.fill((255, 0, 0)) pos = [175, 125] 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: pos[0] += width if event.key == pygame.K_LEFT: pos[0] -= width if event.key == pygame.K_DOWN: pos[1] += height if event.key == pygame.K_UP: pos[1] -= height screen.blit(background, (0, 0)) screen.blit(surface, pos) pygame.display.update()