Game Development Reference
In-Depth Information
large sprite.
The next program we make will demonstrate how to play sounds and draw sprites using
Pygame.
Image and Sound Files
Sprites are stored in image files on your computer. There are several different image
formats that Pygame can use. You can tell what format an image file uses by looking at the
end of the file name. For example, the file happy.png is in the PNG format. The image
formats Pygame supports include BMP, PNG, JPG (and JPEG), and GIF.
You can download images from your web browser. On most web browsers, you just
have to right-click on the image in the web page and select Save from the menu that
appears. Remember where on the hard drive you saved the image file. You can also create
your own images with a drawing program like MS Paint or Tux Paint.
The sound file formats that Pygame supports are MID, WAV, and MP3. You can
download sound effects from the Internet just like image files, as long as the sound effects
are in one of these three formats. If you have a microphone, you can also record sounds
with your computer and use them in your games.
Sprites and Sounds Program
This program is the same as the Keyboard and Mouse Input program from the last
chapter. However, in this program we will use sprites instead of plain looking squares. We
will use a sprite of a little man instead of the white player square, and a sprite of cherries
instead of the green food squares. We also play background music and a sound effect when
the player sprite eats one of the cherry sprites.
The Sprites and Sounds Program's Source Code
If you know how to use graphics software such as Photoshop or MS Paint, you can draw
your own images and use the image files in your games. If you don't know how to use these
programs, you can just download graphics from websites and use those image files instead.
The same applies for music and sound files. You can also find images on web sites or
images from a digital camera. You can download the image and sound files from this
topic's website at http://inventwithpython.com/resources/. You can download the source
code in this chapter from the URL http://inventwithpython.com/chapter19.
spritesAndSounds.py
This code can be downloaded from http://inventwithpython.com/spritesAndSounds.py
If you get errors after typing this code in, compare it to the topic's code with the online
diff tool at http://inventwithpython.com/diff or email the author at
al@inventwithpython.com
Search WWH ::




Custom Search