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

(vip2019) #1
Game Programming: Coding for Fun 249

all of their remaining lives on a single bounce off the bottom edge.
This is because the ball could move way below the bottom edge of
the screen if it’s traveling really quickly, and when we reset the
speed, we might not get the ball completely back on the screen by
the next frame.
To solve this, let’s add one line to the end of that if statement:


picy = 499


We move the ball back onto the screen completely after a lost
life by setting the picy to a value, like 499 , that places the ball com-
pletely above the bottom boundary of the screen. This will help our
ball move safely back onto the screen no matter how fast it was
traveling when it hit the bottom edge.
After these changes, version 2.0 looks like Figure 10-6.


Figure 10-6: Version 2.0 of our Smiley Pong game features faster gameplay,
game over, and play again functionality.


Version 2.0 is like a real arcade game, complete with the game
over/play again screen.

Free download pdf