# Chapter 34 try-this: a bouncing ball. # # Add a ball (circle) that moves on its own using dx and dy. Each frame, add # dx to x and dy to y. When the ball hits the left or right edge of the # window, negate dx. When it hits the top or bottom, negate dy. Start with # dx = 3, dy = 2. # # Run with: python exercises/34/01-bouncing-ball.py import pygame pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Bouncing Ball") clock = pygame.time.Clock() # TODO: add the ball position (x, y), its radius, and dx = 3, dy = 2 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # TODO: move the ball, then bounce it off the four edges screen.fill((30, 30, 30)) # TODO: draw the ball pygame.display.flip() clock.tick(60) pygame.quit()