[BLANK_AUDIO] This is our final lecture in the XNA audio module. So, as a final reminder of the module 12 learning objectives, here you go. Last time, we learned how we could integrate exact audio assets into our XNA games. The problem is that as I record these lectures, MonoGame doesn't support using those exact audio assets in MonoGame games. So we need a different way to add music and sound effects to our MonoGame games, and that's what I'm going to cover today, is how we can actually do that. So we're essentially going to be doing the same game that we did last time using exact audio, though this time we'll do it without using exact audio. I've made significant changes for the audio part of the game, and then commented them all out so that I can reveal them to you as we go through this lecture. So, let's go right to the code. We'll start at the game one class. And I'll show you that I have some additional or different fields declared at the top. And let's start, we're going to do it in a slight different order, because music is actually more complicated this way than it was when we were doing the exact stuff. So we will do music last. We'll do our button click first. So the big idea behind doing sound effects without using exact is that we're going to use a sound effect object for each of our sound effects. So let's go to the place where we create our menu button. So I've changed over to the menu button class. And we'll see that the menu button field, I've now, the menu button class now has a field called button click, and it is the data type sound effect. So I'm going to uncomment that. And I'm also going to come down here to the constructor for the Menu button, and show you that what happens is we actually need to load content. And it's a sound effect this time. It's not a Texture2d. It's a different data type. This time, it's a sound effect. And we give it the name of the sound effect we're going to use. Now if you look over here in the content area My sound effects are just WAV files that I've added as content. We no longer have an exact project that we add as content. We actually add the RAW WAV files as content to our project instead. Okay, so now, because I have this asset called button click, as you can see over here with its name. I can load that asset just like I've been loading texture 2Ds, but this time it's going to load it as a sound effect, which is a WAV file. So, now if I go one more thing I need to change before we actually get a click. If we go over here and we say, when they have pressed the left mouse button on top of this menu button, take the button click sound effect, which I just created the object for in my constructor, and play it. So if I f5 at this point, I get a click when I click on the play button, or on the grid button. I'll click on the grid button, and as you can see we get a click. So the next thing that I'm going to do, is I will add the destroy sound effect because that's the next easier thing to do. So back in our game 1 class. Just like I needed a sound effect for the button click, I need a sound effect for destroy, so I'll uncomment that sound effect. And the next thing I need to do is actually load its content, so I'll come down here to load content. And this particular sound effect was called Zombie. That was the name of the WAV file, so that's the name of the asset. And this is unfortunately one of those areas where exact is really useful, because you don't care what the WAV files are named. You just use cue names when you're using the exact audio assets, but we don't get that capability here, so that's just the way it is. And so we'll use the Zombie WAV file and of course you could change the WAV file name to destroy as well, if you wanted to. And then the last thing we need to do, is we need to make it so that the zombie sound effect plays when the fish eats the bear. So recall that was down in Update. The line two, it was down in the check and resolve fish bear collisions. And so here's where the fish ate the bear, so we're going to play that sound. And now, when I f5, this time of course, I'll pick play. [SOUND] As I drive around eating the teddy bears, you see that it plays that destroy sound. We still don't get a bounce sound. I can dribble a teddy bear. We still don't get a bounce sound, because we haven't played to that one yet. So, let's actually do that one next because again, we have a little extra complication. Remember the way we implemented our exact project, was we set it up so that the bounce sound randomly picked between one of two sound effects, or cues. no sorry. Between two sounds in the sound bank. For a single cue, and it randomly picked between them. Well we don't get that capability without using exact, so we need to implement it ourselves. But we can. We understand how to randomly pick between a few things. We did this way back when we were randomly picking a character to display when we clicked on characters with the mouse, back in the XNA input module. So, we know we can do this. It's just a little extra work for us. So, this time, I've declared a variable called bounce, but this is a two dimensional array of sound effects, so sound effect there. Sorry, it's a two element, one dimensional array of sound effects. And so we're going to basically put a couple of sound effects into this array, and then randomly pick between them. And that's why I have this random number generator here as well. Back to load content so that we can load the content for those sound effects. So, bounce zero, the zero element to the array get's the confetti sound effect loaded into it by the content manager. And the, the first, the oneth element of the array gets the pirate sound effect loaded into it. So at this point we now have the bounce array that contains two sound effects, and again we're at check and resolve fish bear collision. And this time we played the bouncing sound, but notice that I've added this part. So I'm going to randomly going to pick a number that is either 0 or 1. And use that as the index into the array to play that particular sound effect. And so that way I get that same random sound effect getting played on a bounce behavior that I want. And now we can f5 again. And I'll play, and I'll make sure [SOUND] I'm bouncing and as you can see we're getting some random bouncing sound effects each time the teddy bear hits the fish. So, that's it for the sound effects that we have designed and implemented, [LAUGH] I guess. So we button click on menu buttons. We play the zombie sound when the fish eats the bear, and we have the bouncing sound. The last thing that we need is our background music. And I said I was putting that off til last, because it's a little more complicated. It's not hugely complicated, it's just a little more complicated. And here's what adds the complication. The complication is that we have no capability to make sound effects loop. And, what we want for our background music is, we want it to loop while the player is playing the game. So, instead of using a sound effect, I need to use something called a sound effect instance. Let's go to the load content method and see how we handle that. So I'll uncomment these four lines of code. The first thing we do is we actually load a sound effect, because a sound effect instance starts from a sound effect. So, this line of code is just like the other sound effect loading things we've done. The next thing we do though, is we take that sound effect, which is an object, and we call the create instance method on it. And what that does is it creates and returns a sound effect instance object, which we're putting into the background music field. Once we've done that, we can access the Is Looped property of this sound effect instance object, and set it to true. So now we've made it loop. And then we play the background music just like we played the background music, or just like we've played sound effects. This time we're playing a sound effect instance, but we just call the play method, and the background music started playing. But because we set this Is Looped property, this, the background music will loop while we're playing the game. [MUSIC] So, I'll play it one more time. And now we see that we actually do have the sound effect playing, and that's great news. So, in this lecture, that's it for the code. We've added the sound effects just like we did in the previous lecture, except we did it without using an exact project. We did it using the sound effect and sound effect instance classes. And that's what you need to do, at least at the time of the recording of this video for, if you're using MonoGame. And so that's it for this module as well. We learned how to, if you're using exact, how to create an exact project and integrate those audio assets into your game. And if you're using MonoGame, we learned how you could just use WAV files and sound effect and sound effect instances to add music and audio to your game. Next time, we're actually going to talk about how we can use keyboard input and provide text output in our XNA games.