Adding Sounds in PY Games

Updated: February 17, 2022
No Credit Card Required


Today we're going to synchronize the sounds that we added to the action on the display. We're also going to review using sounds and images from other creators.

But before we start, please go to Create new a new Repl, and name it PGD_16_finalmods.

Wwe want to play each sound when a certain event occurs, we want to sync the sounds to the event on the display. For example, when the ship moves up, you want to play the move up sound. To do this, please add a CALL.PLAY whenever you handle that Event. Here we're adding the call to coincide with the K up key, please add this to your Repl.

Now add the call for the move down key K down. Here's what you should have added. And here's the complete code.

When our player collides with an enemy, we need to stop any other sound effects first, because in a collision the player is no longer moving. Let's see how we might do that. For a collision between the player and an enemy, you play the sound for when collisions are detected. We can use a Conditional Statement here. Let's add this code. If sprite_collide any is equal to true, you stop any other sound effects first, because in a collision, the players not moving.

Then you play the collision sound and continue execution from there. Finally, when the game's all over, all sound should stop. This is true whether the game ends due to a collision, or the user exits manually. To do this, add the following lines at the end of the program after the loop, go ahead and add it now.

We want to cover the laws on using other people's content that you source online. There are many online sources for music, sound and art that you can search for useful content. However, each piece of content is made available to you under a specific set of terms complying with the licensing terms is very important. You know, you can get in legal trouble.

For example, with our background music, the creator required that in order to use the sound, both proper attribution who created it, and a link to the license must be provided. Please make sure you understand and follow the licensing terms.

Well, we've put the finishing touches on our game, but there is so much more that you can do with PI games. I encourage you to keep working on your game and to move on to you codes Python Fundamentals course which is the next level in our Python progression.

And finally - drum roll please – you have graduated from this course and you have done some great work.

I really enjoyed working with you and I hope to see you in one of my other classes. Oh Um Don't forget to make sure that you order your course completion certificate from

Okay, that's it. Bye