O'Reilly logo

Adventures in Python by Craig Richardson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ch09-pag203

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required