If you’ve seen my other posts you know I’m building a Police Chase game for my final project in a programming course, but I’m using sections 3 and 4 as a framework for what will be a rail-shooter setup like Argon Assault in the next section. I don’t have a rocket but I’m learning the same concepts for my own application.
I gave the police car a siren, but went a little bit above and beyond to make it more realistic. You can press the up, down, left or right arrow keys to move and turn, but the siren won’t begin until you press UP to start moving. Once you’re stopped, the siren will start again as soon as you move forward as if you’re going to start chasing again. You can also press ‘S’ on the keyboard to start or stop the siren at any time.
As you’ll see in my code, this is very easy. Basically all I did was say "if the audio is muted then play it (mute = false), and if it’s already playing then mute it (mute = true). Hope ya like it.