SPEAKER: All right.
So now we have a fully functioning, more or less, Mario game.
Well, you know, without the AI, without the levels,
but the platforming scaffolding is there.
If you wanted to take this code base and iterate
upon it, which will actually be part of the assignment,
you're more than free to do so, of course.
In this update, you know we have a screenshot, although it doesn't really
mean much here because this is just a sound-based update,
we're going to add a music track and sound effects.
And actually, it's really easy to do this.
I'm going to go over to my code editor.
Here's my map.Lua file.
All we need to do, and this is very similar to what we did before,
is just add a new audio source, which is what we did in Pong.
Because music and sound effects really aren't treated any differently.
So right here, I've added a sound such music.wav.
I found a sound file on freesound.org that allows
you to use royalty-free music, which is included in the distro you'll have.
And all I'm doing is declaring it as static.
You could declare it as stream, again, if you wanted to,
but I'm declining it static so it stays in memory.
And so if we go down to the bottom of the init function here for the map,
you'll see that I have a few other function calls.
We have setLooping to true.
I want the music to always keep playing over and over again,
even when it hits the end because, otherwise, it'll
be kind of weird for the music to just kind of stop cold.
The music is a little loud, so we set it to 0.25 volume.
So this is between zero and one floating point value.
So 0.25 is about a quarter of the volume of the original soundtrack.
And then, finally, when we hit play, that
actually triggers the sound to start playing,
as we've seen before when we did Pong.
Now, we also wanted to add some sound effects to the game.
So over in the Player class, I went ahead
and created a table called self.sounds with a jump, hit,
and coin sound, which, again, jump, hit, and coin.
I used a BFXR to generate these sound effects, as we saw at the end of Pong.
And if we go across over to, let's say, the idle stage, and we go to jumping,
let's say over here.
If we press the spacebar, and we activate our jump,
you can see that I'm calling the jump sound here with colon play.
And if we go down here, I'm just going to do a search for colon play,
just for ease here.
So we are also keeping track of whether or not we hit a block,
and it is going from yellow to brown, or whether it is already a brown tile.
So we're checking to see whether we have hit a jump block,
or whether we've hit a jump block hit.
And accordingly, we can play either the coin sound or the hit sound.
And those are the only sound effects that we are adding to Mario.
Let's go ahead and give this a test run right now.
[MUSIC PLAYING]
So we spawned actually in front of a pit there and almost fell off.
If I jump, you can hear the jump sound effect.
Let's find a tile.
OK.
So there's no blocks.
So I'm going to go ahead and run it one more time.
This is the part of a procedurally generated landscape
is you want to always have a block.
So let's try it again.
Here we go.
This is perfect.
We'll jump.
We hit it.
We got the sound of the coin.
And now if I jump again, you can hear that there
was a little bit of a thud sound.
So it's as a little bit of polish.
It really kind of completes the game, in my opinion.
And I'm a big fan.
And it feels really good to have tied it all together
and have something that feels more or less complete and playable.
So that was it for the Mario track and, therefore, the end of the game's track.
Now, there is an assignment associated with this half of the track,
just like there was for Pong.
And this actually ties back nicely to CS50 itself.
In p set one, you implemented a pyramid with Mario's hash marks.
In this case, in the Mario assignment here, we're
going to have you implement an actual pyramid that looks something like this.
And then we want this to be part of the level generation.
And then anywhere else in the level, you can either
do it like here where it goes straight to the flag,
or you can put this in the middle and then have the flag at the end.
But either way, you need to add a flag.
And we provided this in the sprite sheet.
There's an actual set of flags sprites for the flag itself and the pole.
And when Mario hits this flag pole, when it touches it or goes past it,
I want this to trigger some message that says you have beat the game,
or this is the end of the level.
If you want to, you can even re-trigger a new level,
if you want to go sort of above and beyond.
But that'll be it for the Mario assignment.
So this is CS50.
This was the game's track.
It was a pleasure having you.
See you next time.