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

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

Figure 10-7: The SmileyPop app is more like a game now that we’ve
added sound and a progress/feedback display.

The popping sound and progress display feedback have made
SmileyPop feel like a mobile app. As you’re popping smiley faces by
right-clicking, you can probably imagine tapping the smileys with
your finger to pop them on a mobile device. (To learn how to build
mobile apps, check out MIT’s App Inventor at http://appinventor
.mit.edu/.)

Putting It All Together


Here’s the complete code for SmileyPop, version 2.0. Remember to
keep the .py source code file, the CrazySmile.bmp image file, and
the pop.wav sound file all in the same folder.
At almost 90 lines, this app might be a bit too long to type by
hand. Go to http://www.nostarch.com/teachkids/ to download the
code, along with the sound and picture files.

SmileyPop2.py


import pygame
import random


BLACK = (0,0,0)
WHITE = (255,255,255)

Free download pdf