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.
I copied the file into the directory, and created this variable:
// The sound used when the player is hitI've loaded the content like this:
SoundEffect playerHit;
// 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 hitWhen 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.
playerHit.Play();
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.