import pygame # Homework: move a shape with the arrow keys. # Use pygame.key.get_pressed() and the constants: # pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN # The shape should wrap around: when it exits one edge it reappears # on the opposite side. pygame.init() screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("Arrow Keys") clock = pygame.time.Clock() BG = (20, 20, 20) RED = (220, 60, 60) RADIUS = 25 x = 320.0 y = 240.0 speed = 5 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False keys = pygame.key.get_pressed() # TODO: update x and y based on arrow key presses # TODO: wrap x: if x < -RADIUS then x = 640 + RADIUS, and vice versa # TODO: wrap y: if y < -RADIUS then y = 480 + RADIUS, and vice versa screen.fill(BG) pygame.draw.circle(screen, RED, (int(x), int(y)), RADIUS) pygame.display.flip() clock.tick(60) pygame.quit()