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

(vip2019) #1

236 Chapter 10


the bottom of the screen. Our next task is to add logic to make the
ball bounce off the paddle and gain points, as well as to subtract a
life when the ball hits the bottom of the screen. Figure 10-3 shows
what your game might look like after a player gains some points.
Notice how the point display has been updated to 8.

Figure 10-3: As the smiley ball bounces off the paddle at the bottom,
we’ll add points to our player’s score.

As mentioned earlier, we’ll start our game with zero points and
five lives in the setup portion of our code:

points = 0
lives = 5

Next we have to figure out when to add to points and when to
take away from lives.

Subtracting a Life
Let’s start with subtracting a life. We know that if the ball hits
the bottom edge of the screen, the player has missed it with the
paddle, so they should lose a life.
Free download pdf