IN THIS ADVENTURE, you’ll learn how to use sounds and music with Python and PyGame
. PyGame
makes sounds and music available, including a whole load of useful functions that make it straightforward to add them to your program.
You’ll make a loop that plays sounds, sounds that play when you press the keys on the keyboard and a basic music player. On top of this, you’ll improve the sprite walking program that you made in Adventure 8 by adding music and sounds to it.
Before you start, you’ll need to download the sample sounds and music needed for this adventure. You can find out how to do this in the Appendix. Make sure you save the files in the Adventure 9
folder.
Let’s get going.
Playing Sounds
In this first program, you’ll learn how to play sounds. The program you make here will form the basis of other programs that you create in the adventure. Sounds are very important in games. They’re an excellent way of sharing information with users and setting tone, all with just some noises. For example, in many video games you can often hear certain enemies sneaking up on you or you can tell if you ...
Get Adventures in Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.