# Homework 34, problem 2: two-ball bounce. # # Two balls start at different positions with different velocities. Both # bounce off all four walls independently. Each ball is a different colour. # # Run with: python exercises/34/homework/02-two-balls.py import pygame pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Two Balls") clock = pygame.time.Clock() ax, ay, adx, ady = 200, 150, 4, 3 bx, by, bdx, bdy = 600, 400, -3, 5 radius = 20 W, H = 800, 600 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # TODO: move ball a and bounce it off the four walls # TODO: move ball b and bounce it off the four walls screen.fill((10, 10, 10)) pygame.draw.circle(screen, (255, 80, 80), (ax, ay), radius) pygame.draw.circle(screen, (80, 180, 255), (bx, by), radius) pygame.display.flip() clock.tick(60) pygame.quit()