External Exam Download Resources Web Applications Games Recycle Bin

Key spammer game

spacebar_circle.py

import pygame
white = (255, 255, 255) # RGB
blue = (0,0,255)
pygame.init()
screen = pygame.display.set_mode((400, 300))
clock = pygame.time.Clock() # allows us to throttle frame rate
done = False

radius = 10

while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    elif event.type == pygame.KEYDOWN:
      if event.key == pygame.K_SPACE:
        radius = radius + 10 # spam the spacebar

  screen.fill(white)
  pygame.draw.circle(
    screen,    # surface to draw to
    blue,      # colour
    (150,150), # (centerX, centerY)
    radius     # radius
  )
  pygame.display.flip()
  radius = radius * 0.99 # gradually decrease the radius
  clock.tick(60) # caps at 60fps
  
pygame.quit()