250 Chapter 10
Putting It All Together
Here’s our finished version 2.0, SmileyPong2.py. At just under
80 lines of code, it’s a full arcade-style game that you can show off
to friends and family. You can also build on it further to develop
your coding skill.
SmileyPong2.py
import pygame # Setup
pygame.init()
screen = pygame.display.set_mode([800,600])
pygame.display.set_caption("Smiley Pong")
keepGoing = True
pic = pygame.image.load("CrazySmile.bmp")
colorkey = pic.get_at((0,0))
pic.set_colorkey(colorkey)
picx = 0
picy = 0
BLACK = (0,0,0)
WHITE = (255,255,255)
timer = pygame.time.Clock()
speedx = 5
speedy = 5
paddlew = 200
paddleh = 25
paddlex = 300
paddley = 550
picw = 100
pich = 100
points = 0
lives = 5
font = pygame.font.SysFont("Times", 24)
while keepGoing: # Game loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_F1: # F1 = New Game
points = 0
lives = 5
picx = 0
picy = 0
speedx = 5
speedy = 5