Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

234 Chapter 10


Figure 10-2: The Smiley Pong game we’ll build

The first feature we’ll add to the former SmileyBounce2.py app
is the paddle.

Drawing a Board and Game Pieces


In our finished game, the paddle will move along the bottom of the
screen, following the mouse’s movement as the user tries to keep
the ball from hitting the bottom edge.
To get the paddle started, we’ll add this information to the
setup section of our app:

WHITE = (255,255,255)
paddlew = 200
paddleh = 25
paddlex = 300
paddley = 550

These variables will help us create a paddle that is simply a
white rectangle of width 200 and height 25. We’ll want the coordi-
nates of its top-left corner to start at (300, 550) so that the paddle
starts off slightly above the bottom edge and centered horizontally
on the 800 × 600 screen.
Free download pdf