1 00:00:00,000 --> 00:00:00,792 SPEAKER: All right. 2 00:00:00,792 --> 00:00:03,480 So now we have a fully functioning, more or less, Mario game. 3 00:00:03,480 --> 00:00:06,060 Well, you know, without the AI, without the levels, 4 00:00:06,060 --> 00:00:07,830 but the platforming scaffolding is there. 5 00:00:07,830 --> 00:00:10,200 If you wanted to take this code base and iterate 6 00:00:10,200 --> 00:00:11,790 upon it, which will actually be part of the assignment, 7 00:00:11,790 --> 00:00:13,720 you're more than free to do so, of course. 8 00:00:13,720 --> 00:00:16,230 In this update, you know we have a screenshot, although it doesn't really 9 00:00:16,230 --> 00:00:18,870 mean much here because this is just a sound-based update, 10 00:00:18,870 --> 00:00:21,270 we're going to add a music track and sound effects. 11 00:00:21,270 --> 00:00:22,710 And actually, it's really easy to do this. 12 00:00:22,710 --> 00:00:24,335 I'm going to go over to my code editor. 13 00:00:24,335 --> 00:00:27,060 Here's my map.Lua file. 14 00:00:27,060 --> 00:00:30,450 All we need to do, and this is very similar to what we did before, 15 00:00:30,450 --> 00:00:33,743 is just add a new audio source, which is what we did in Pong. 16 00:00:33,743 --> 00:00:36,660 Because music and sound effects really aren't treated any differently. 17 00:00:36,660 --> 00:00:39,220 So right here, I've added a sound such music.wav. 18 00:00:39,220 --> 00:00:43,830 I found a sound file on freesound.org that allows 19 00:00:43,830 --> 00:00:48,390 you to use royalty-free music, which is included in the distro you'll have. 20 00:00:48,390 --> 00:00:50,340 And all I'm doing is declaring it as static. 21 00:00:50,340 --> 00:00:52,320 You could declare it as stream, again, if you wanted to, 22 00:00:52,320 --> 00:00:54,600 but I'm declining it static so it stays in memory. 23 00:00:54,600 --> 00:00:58,787 And so if we go down to the bottom of the init function here for the map, 24 00:00:58,787 --> 00:01:00,870 you'll see that I have a few other function calls. 25 00:01:00,870 --> 00:01:02,550 We have setLooping to true. 26 00:01:02,550 --> 00:01:05,050 I want the music to always keep playing over and over again, 27 00:01:05,050 --> 00:01:06,660 even when it hits the end because, otherwise, it'll 28 00:01:06,660 --> 00:01:09,510 be kind of weird for the music to just kind of stop cold. 29 00:01:09,510 --> 00:01:12,910 The music is a little loud, so we set it to 0.25 volume. 30 00:01:12,910 --> 00:01:16,000 So this is between zero and one floating point value. 31 00:01:16,000 --> 00:01:19,950 So 0.25 is about a quarter of the volume of the original soundtrack. 32 00:01:19,950 --> 00:01:21,840 And then, finally, when we hit play, that 33 00:01:21,840 --> 00:01:23,880 actually triggers the sound to start playing, 34 00:01:23,880 --> 00:01:26,550 as we've seen before when we did Pong. 35 00:01:26,550 --> 00:01:29,222 Now, we also wanted to add some sound effects to the game. 36 00:01:29,222 --> 00:01:30,930 So over in the Player class, I went ahead 37 00:01:30,930 --> 00:01:34,590 and created a table called self.sounds with a jump, hit, 38 00:01:34,590 --> 00:01:37,320 and coin sound, which, again, jump, hit, and coin. 39 00:01:37,320 --> 00:01:41,730 I used a BFXR to generate these sound effects, as we saw at the end of Pong. 40 00:01:41,730 --> 00:01:48,720 And if we go across over to, let's say, the idle stage, and we go to jumping, 41 00:01:48,720 --> 00:01:49,865 let's say over here. 42 00:01:49,865 --> 00:01:51,990 If we press the spacebar, and we activate our jump, 43 00:01:51,990 --> 00:01:56,880 you can see that I'm calling the jump sound here with colon play. 44 00:01:56,880 --> 00:02:00,660 And if we go down here, I'm just going to do a search for colon play, 45 00:02:00,660 --> 00:02:02,460 just for ease here. 46 00:02:02,460 --> 00:02:07,080 So we are also keeping track of whether or not we hit a block, 47 00:02:07,080 --> 00:02:11,263 and it is going from yellow to brown, or whether it is already a brown tile. 48 00:02:11,263 --> 00:02:13,680 So we're checking to see whether we have hit a jump block, 49 00:02:13,680 --> 00:02:15,600 or whether we've hit a jump block hit. 50 00:02:15,600 --> 00:02:20,632 And accordingly, we can play either the coin sound or the hit sound. 51 00:02:20,632 --> 00:02:23,340 And those are the only sound effects that we are adding to Mario. 52 00:02:23,340 --> 00:02:25,590 Let's go ahead and give this a test run right now. 53 00:02:25,590 --> 00:02:27,870 [MUSIC PLAYING] 54 00:02:27,870 --> 00:02:32,010 So we spawned actually in front of a pit there and almost fell off. 55 00:02:32,010 --> 00:02:34,820 If I jump, you can hear the jump sound effect. 56 00:02:34,820 --> 00:02:35,920 Let's find a tile. 57 00:02:35,920 --> 00:02:36,420 OK. 58 00:02:36,420 --> 00:02:37,140 So there's no blocks. 59 00:02:37,140 --> 00:02:39,223 So I'm going to go ahead and run it one more time. 60 00:02:39,223 --> 00:02:41,820 This is the part of a procedurally generated landscape 61 00:02:41,820 --> 00:02:42,810 is you want to always have a block. 62 00:02:42,810 --> 00:02:43,650 So let's try it again. 63 00:02:43,650 --> 00:02:44,150 Here we go. 64 00:02:44,150 --> 00:02:44,910 This is perfect. 65 00:02:44,910 --> 00:02:45,990 We'll jump. 66 00:02:45,990 --> 00:02:46,530 We hit it. 67 00:02:46,530 --> 00:02:48,060 We got the sound of the coin. 68 00:02:48,060 --> 00:02:51,695 And now if I jump again, you can hear that there 69 00:02:51,695 --> 00:02:53,070 was a little bit of a thud sound. 70 00:02:53,070 --> 00:02:54,570 So it's as a little bit of polish. 71 00:02:54,570 --> 00:02:56,737 It really kind of completes the game, in my opinion. 72 00:02:56,737 --> 00:02:57,660 And I'm a big fan. 73 00:02:57,660 --> 00:02:59,868 And it feels really good to have tied it all together 74 00:02:59,868 --> 00:03:03,060 and have something that feels more or less complete and playable. 75 00:03:03,060 --> 00:03:06,618 So that was it for the Mario track and, therefore, the end of the game's track. 76 00:03:06,618 --> 00:03:09,410 Now, there is an assignment associated with this half of the track, 77 00:03:09,410 --> 00:03:10,618 just like there was for Pong. 78 00:03:10,618 --> 00:03:13,470 And this actually ties back nicely to CS50 itself. 79 00:03:13,470 --> 00:03:18,120 In p set one, you implemented a pyramid with Mario's hash marks. 80 00:03:18,120 --> 00:03:20,850 In this case, in the Mario assignment here, we're 81 00:03:20,850 --> 00:03:24,840 going to have you implement an actual pyramid that looks something like this. 82 00:03:24,840 --> 00:03:27,630 And then we want this to be part of the level generation. 83 00:03:27,630 --> 00:03:29,820 And then anywhere else in the level, you can either 84 00:03:29,820 --> 00:03:32,327 do it like here where it goes straight to the flag, 85 00:03:32,327 --> 00:03:35,160 or you can put this in the middle and then have the flag at the end. 86 00:03:35,160 --> 00:03:37,440 But either way, you need to add a flag. 87 00:03:37,440 --> 00:03:39,540 And we provided this in the sprite sheet. 88 00:03:39,540 --> 00:03:43,620 There's an actual set of flags sprites for the flag itself and the pole. 89 00:03:43,620 --> 00:03:48,150 And when Mario hits this flag pole, when it touches it or goes past it, 90 00:03:48,150 --> 00:03:51,450 I want this to trigger some message that says you have beat the game, 91 00:03:51,450 --> 00:03:52,890 or this is the end of the level. 92 00:03:52,890 --> 00:03:55,057 If you want to, you can even re-trigger a new level, 93 00:03:55,057 --> 00:03:57,030 if you want to go sort of above and beyond. 94 00:03:57,030 --> 00:03:59,110 But that'll be it for the Mario assignment. 95 00:03:59,110 --> 00:04:00,030 So this is CS50. 96 00:04:00,030 --> 00:04:01,132 This was the game's track. 97 00:04:01,132 --> 00:04:02,340 It was a pleasure having you. 98 00:04:02,340 --> 00:04:04,310 See you next time. 99 00:04:04,310 --> 00:04:05,526