Game Programming: Coding for Fun 241
if picx + picw/2 >= paddlex and picx + picw/2 <= paddlex + \
paddlew:
points += 1
speedy = -speedy
Adding a point is easy: points += 1. Changing the direction of
the ball so it looks like it bounced off the paddle is easy too; we
just reverse our speed in the y direction to make it go back up the
screen: speedy = -speedy.
You can run the program with those changes and see the ball
bounce off the paddle. Each time the paddle hits the ball, you’re
earning a point, and whenever the ball misses the paddle, you’re
losing a life, but we’re not showing those on the screen yet. Let’s do
that next.
Showing the Score
We have the logic we need to add points and subtract lives, but we
don’t see the points on the screen as we play. In this section, we’ll
draw text to the screen to give the user feedback while they’re
playing, as shown in Figure 10-5.
Figure 10-5: Smiley Pong, version 1.0, is becoming a real game!