# Homework 35, problem 2: countdown timer. # # Display a timer that counts down from 10 to 0. Use clock.tick(60) to # control speed, and track elapsed time by adding 1/60 to a float # accumulator each frame. When the counter reaches 0, display "Time's up!" # and stop counting. # # Run with: python exercises/35/homework/02-countdown.py import pygame pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Countdown") clock = pygame.time.Clock() font = pygame.font.SysFont("arial", 64) small = pygame.font.SysFont("arial", 36) elapsed = 0.0 DURATION = 10.0 done = False running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # TODO: add 1 / 60 to elapsed each frame until the countdown is done screen.fill((20, 20, 40)) # TODO: draw the remaining seconds, or "Time's up!" when done pygame.display.flip() clock.tick(60) pygame.quit()