Wednesday, September 14, 2011

Let's Make a Game! Episode 19: Timing Is Everything

Well, that was easy enough.

Since we already had the variables in place to fix the timing of our weapon, it was merely a matter of throwing in an if -> then command. Done and done.
So now, I thought it would be a good idea to give some indicator to the player that their ship has been damaged. Otherwise, the only way you know if you've been hit is by looking in the upper right-hand corner and seeing your health drop by a bit. There's a few things we could do:
  • A physical cue. Your ship could shake or something like that.
  • An audio cue.
The audio cue is easier to make, I think. Plus, while you may miss the subtle shake of your ship, you can't avoid a sound that makes your character yell, right? I found a freeware sound of someone screaming "Ow," so let's see if I can toss it in.

I copied the file into the directory, and created this variable:
// The sound used when the player is hit
SoundEffect playerHit; 
I've loaded the content like this:
// Load the "playerhit" sound effect
playerHit = Content.Load("sound/ouch");

And then placed the reference in the area it should be:
// Play an audio cue to show us we got hit
When I run it, it says that the file "Sound/ouch" doesn't exist. How can that be? We've loaded the content, right? It's in the right folder, correct? That should be all we need to do, I would think. Yet, we're getting nothing. Huh.

I fiddled around in the MSDN looking for answers but couldn't get anywhere. Finally, I noticed this little guy sitting in Visual Studio:

Figuring I didn't have anything to lose, I navigated to the folder where I had saved my "ouch.wav" file and drag-and-dropped the file into this Sound folder.

I run my program...

And it works! My character now screams every time he gets hit! Woo-hoo! I've made someone yell in pain repeatedly!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.