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

(vip2019) #1
Timers and Animation: What Would Disney Do? 201

Figure 8-9: If we comment out the line that clears our screen after each
frame, our smiley face leaves a bouncing trail behind in a cool pattern.

What you learned


In this chapter, you learned how to create the illusion of motion,
what we call animation, by drawing images in different locations
on the screen over time. We saw how the Pygame module can make
programming a game or animation much quicker, since it has hun-
dreds of functions that can make almost everything in a game app
easier, from drawing images to creating timer-based animation—
even checking for collisions. We installed Pygame on our computer
so we could use its features to create fun apps of our own.
You learned about the structure of a game or app that we might
build in Pygame, with a setup section; a game loop that handles
events, updates and draws graphics, and then updates the display;
and finally an exit section.
We started our Pygame programming by drawing a simple
green dot on the screen at a chosen location, but we quickly moved
on to drawing a picture from an image file on disk, saved in the
same folder as our program, to our display screen. You learned
Free download pdf