# Homework 33 solution, problem 3: arrow mover. # Run with: python exercises/33/homework/solutions/03-arrow-mover.py import pygame pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Arrow Mover") clock = pygame.time.Clock() cx, cy = 400, 300 speed = 4 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False keys = pygame.key.get_pressed() moving = False if keys[pygame.K_LEFT]: cx -= speed moving = True if keys[pygame.K_RIGHT]: cx += speed moving = True if keys[pygame.K_UP]: cy -= speed moving = True if keys[pygame.K_DOWN]: cy += speed moving = True if moving: print("moved") screen.fill((30, 30, 30)) pygame.draw.circle(screen, (255, 100, 100), (cx, cy), 30) pygame.display.flip() clock.tick(60) pygame.quit()