import pygame import sys pygame.init() screen = pygame.display.set_mode((400, 300)) background = pygame.Surface((400, 300)) surface = pygame.Surface((10, 10)) detail = pygame.Surface((4, 4)) surface.fill((0,255,0)) detail.fill((255, 0, 0)) detailpos = [175, 125] POS = [172, 122] 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] += 20 detailpos[0] += 20 if event.key == pygame.K_LEFT: POS[0] = POS[0] - 20 detailpos[0] = detailpos[0] - 20 if event.key == pygame.K_DOWN: POS[1] += 20 detailpos[1] += 20 if event.key == pygame.K_UP: POS[1] = POS[1] - 20 detailpos[1] = detailpos[1] - 20 screen.blit(background, (0, 0)) screen.blit(surface, POS) if POS > [400] or POS < [0]: pygame.quit() sys.exit() screen.blit(detail, detailpos) pygame.display.update()