228 Chapter 9
In our closing example, we added sprite-based collision detec-
tion to see whether the user right-clicked the mouse over one or
more smiley sprites. We saw how to check for events on the left
mouse button separately from the right mouse button. We learned
that Python has powerful features for selecting items out of a list
based on an if condition, and we saw how to remove sprites from a
Group using the remove() function.
We created fun apps in this chapter, topped off by a SmileyPop
app that we’ll make even more game-like in Chapter 10. Pygame
has given us the final skills we need to program awesome games!
Programming the cool apps in this chapter has given us the
skills to do the following:
• Use sprite graphics by customizing the pygame.sprite.Sprite()
class.
• Access, modify, update, and draw a list of sprites using pygame
.sprite.Group() and its functions.
• Transform an image by applying the pygame.trasform.scale()
function to increase or decrease the image’s size in pixels.
• Detect sprite collisions using rect.collidepoint() and similar
functions from the Sprite class.
• Remove sprites from a Group using the remove() function.
Programming Challenges
Here are three challenge problems to extend the skills
developed in this chapter. For sample answers to these
challenges, go to http://www.nostarch.com/teachkids/.
#1: Randomly Colored Dots
Start by choosing your own color triplet to use in the
DragDots.py program. Then modify the program to draw
randomly colored dots by creating a triplet of three random
numbers between 0 and 255 to use as your colors. Call your
new creation RandomPaint.py.