WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000 00:00:00.000 --> 00:00:02.470 [MUSIC PLAYING] 00:00:17.300 --> 00:00:20.840 BRIAN YU: Welcome back, everyone, to now our final class in this Introduction 00:00:20.840 --> 00:00:22.160 to Programming with Scratch. 00:00:22.160 --> 00:00:25.040 And at this point, we've seen most of the major features 00:00:25.040 --> 00:00:26.280 that Scratch has to offer. 00:00:26.280 --> 00:00:28.670 So today in this final class, what we thought we'd do 00:00:28.670 --> 00:00:31.580 is show you a few additional features that you might find useful 00:00:31.580 --> 00:00:33.380 as you go about building your own projects 00:00:33.380 --> 00:00:36.620 and then show you how you could put the pieces together, so to speak, 00:00:36.620 --> 00:00:40.430 and use all of the tools and the ideas that we've explored during this course 00:00:40.430 --> 00:00:44.510 to see how you could put them together to create a complete game using 00:00:44.510 --> 00:00:45.440 Scratch. 00:00:45.440 --> 00:00:48.620 So let's go ahead and begin by taking a look at a couple final features 00:00:48.620 --> 00:00:50.030 of Scratch to introduce. 00:00:50.030 --> 00:00:54.540 And the first involves how it is that sprites communicate with each other. 00:00:54.540 --> 00:00:56.420 You might recall that in an earlier project, 00:00:56.420 --> 00:00:59.267 we had a cat talking to a dinosaur, for example. 00:00:59.267 --> 00:01:01.100 And how we did that was something like this. 00:01:01.100 --> 00:01:05.239 I had a cat, and then I added the dinosaur, which 00:01:05.239 --> 00:01:07.430 I'll go ahead and find and bring back. 00:01:07.430 --> 00:01:10.020 I wanted the cat and the dinosaur to be facing each other. 00:01:10.020 --> 00:01:12.620 So I took the dinosaur and I set its rotation 00:01:12.620 --> 00:01:16.440 to left right and then set its direction to negative 90 00:01:16.440 --> 00:01:18.240 so it was facing the other way. 00:01:18.240 --> 00:01:21.320 And if I wanted the cat and the dinosaur to greet each other, 00:01:21.320 --> 00:01:29.390 then I would have the cat when the flag is clicked do something like say hello 00:01:29.390 --> 00:01:32.330 to the dinosaur. 00:01:32.330 --> 00:01:35.810 And then likewise for the dinosaur, if I want the dinosaur to respond 00:01:35.810 --> 00:01:38.000 to the cat saying hello, well, the cat is 00:01:38.000 --> 00:01:40.430 saying hello dinosaur for two seconds. 00:01:40.430 --> 00:01:44.120 So the dinosaur better wait two seconds before it responds. 00:01:44.120 --> 00:01:46.700 So the dinosaur, I did something like this. 00:01:46.700 --> 00:01:49.850 I said when the flag is clicked, let's go under Control. 00:01:49.850 --> 00:02:00.050 Let's wait two seconds and then say hello to the cat. 00:02:00.050 --> 00:02:03.560 So now when I run the project, the cat says hello dinosaur. 00:02:03.560 --> 00:02:07.580 And immediately after, the dinosaur says hello cat. 00:02:07.580 --> 00:02:09.270 What if I later wanted to make a change? 00:02:09.270 --> 00:02:12.530 I want the cat to only say hello dinosaur for maybe one second, 00:02:12.530 --> 00:02:13.490 for example. 00:02:13.490 --> 00:02:17.450 Well, now the cat speaks and I have this weird pause 00:02:17.450 --> 00:02:20.690 before the dinosaur responds, because I forgot to change 00:02:20.690 --> 00:02:22.610 how long the dinosaur was waiting. 00:02:22.610 --> 00:02:25.010 I'd also have to change that from two to one 00:02:25.010 --> 00:02:27.650 in order to get it to respond appropriately. 00:02:27.650 --> 00:02:30.875 Ultimately, this is going to start to get more complex, especially as there 00:02:30.875 --> 00:02:33.560 are more interactions between these two sprites 00:02:33.560 --> 00:02:35.810 or if later I add other sprites altogether 00:02:35.810 --> 00:02:38.960 for me to have to calculate exactly how long every sprite should 00:02:38.960 --> 00:02:42.560 be waiting in between one thing happening and another thing happening. 00:02:42.560 --> 00:02:46.460 What would be better is if the cat when it was done speaking 00:02:46.460 --> 00:02:50.870 could somehow signal to the dinosaur that it's now the dinosaurs turn 00:02:50.870 --> 00:02:51.800 to start speaking. 00:02:51.800 --> 00:02:53.930 That way I, the programmer, don't have to do 00:02:53.930 --> 00:02:56.210 all this math of figuring out exactly how 00:02:56.210 --> 00:02:58.430 long these sprites should be waiting. 00:02:58.430 --> 00:03:00.530 And so this brings us to one of our final topics 00:03:00.530 --> 00:03:03.080 in Scratch, which is called broadcasting. 00:03:03.080 --> 00:03:07.370 Broadcasting is the ability for one object in Scratch, one sprite, 00:03:07.370 --> 00:03:12.650 for example, to send some message that other sprites like the dinosaur, 00:03:12.650 --> 00:03:14.660 in this case, could receive. 00:03:14.660 --> 00:03:17.900 So we have the ability to send or broadcast messages. 00:03:17.900 --> 00:03:21.290 And then we have the ability for other sprites to receive those messages. 00:03:21.290 --> 00:03:25.672 When they receive a message, the sprites are going to respond in some way. 00:03:25.672 --> 00:03:26.880 So what would that look like? 00:03:26.880 --> 00:03:30.590 How could we broadcast a message from the cat to the dinosaur 00:03:30.590 --> 00:03:34.370 so that the dinosaur knows that it's time to greet the cat? 00:03:34.370 --> 00:03:36.140 Let's go back to the cat. 00:03:36.140 --> 00:03:41.060 And after the cat says hello dinosaur for let's go back to two seconds, 00:03:41.060 --> 00:03:48.710 then under Event, I'm going to use this broadcast block to broadcast a message. 00:03:48.710 --> 00:03:51.080 And I'm going to choose a new message from the dropdown. 00:03:51.080 --> 00:03:52.850 And I can just name this message. 00:03:52.850 --> 00:03:55.400 This is any message that I'm now going to send. 00:03:55.400 --> 00:03:58.730 And I'm going to call the message greet, just because it's 00:03:58.730 --> 00:04:01.460 going to be a message that signals to the dinosaur 00:04:01.460 --> 00:04:03.980 that it's time to greet the cat. 00:04:03.980 --> 00:04:08.030 So the cat says hello dinosaur and then broadcasts greet. 00:04:08.030 --> 00:04:13.280 And the dinosaur now instead of saying hello cat when the flag is clicked, 00:04:13.280 --> 00:04:16.700 I'm going to get rid of the when flag is clicked event entirely 00:04:16.700 --> 00:04:22.670 and replace it with this event here when I receive greet. 00:04:22.670 --> 00:04:26.630 So the cat is first going to say hello dinosaur for two seconds 00:04:26.630 --> 00:04:28.680 and then broadcast this message. 00:04:28.680 --> 00:04:30.650 The message is greet. 00:04:30.650 --> 00:04:34.700 And then the dinosaur when it receives the greet message is then 00:04:34.700 --> 00:04:36.890 going to say hello to the cat. 00:04:36.890 --> 00:04:41.360 And so now the cat says hello dinosaur, and immediately the dinosaur 00:04:41.360 --> 00:04:42.710 responds hello cat. 00:04:42.710 --> 00:04:46.250 The cat broadcasted a message and the dinosaur received it. 00:04:46.250 --> 00:04:48.170 And now it doesn't matter if there's a delay. 00:04:48.170 --> 00:04:52.250 I could add a delay of a second to the cat. 00:04:52.250 --> 00:04:55.700 And so the cat will now wait a second before speaking, 00:04:55.700 --> 00:04:57.830 but the dinosaur still responds right on cue. 00:04:57.830 --> 00:05:00.060 I didn't have to change any of the timing, 00:05:00.060 --> 00:05:03.290 because the cat broadcasted a message once the cat was 00:05:03.290 --> 00:05:08.130 done doing whatever it was doing and the dinosaur was then able to respond. 00:05:08.130 --> 00:05:10.783 So this works great for stories where you have multiple sprites 00:05:10.783 --> 00:05:13.700 and they're interacting in some way and you want some sprite to signal 00:05:13.700 --> 00:05:17.750 to someone else when it's their turn to say something or do something, 00:05:17.750 --> 00:05:18.590 for example. 00:05:18.590 --> 00:05:22.070 It can also be used in other ways to let one sprite control 00:05:22.070 --> 00:05:25.130 or influence the behavior of another sprite. 00:05:25.130 --> 00:05:27.830 Let's imagine that I had a duck. 00:05:27.830 --> 00:05:34.280 Let's add a new animal and let's go back to the duck here. 00:05:34.280 --> 00:05:36.787 And let's say I wanted the duck to move up and down. 00:05:36.787 --> 00:05:38.120 And we could use the arrow keys. 00:05:38.120 --> 00:05:40.280 I could use the up and down arrow keys to control it. 00:05:40.280 --> 00:05:42.363 But I'd like for the user just to be able to click 00:05:42.363 --> 00:05:45.620 on up and down arrows on the screen as some user interface 00:05:45.620 --> 00:05:48.020 that they could use as a visual on the screen that 00:05:48.020 --> 00:05:51.620 lets them control if the duck is going to move up or move down. 00:05:51.620 --> 00:05:53.270 So let's add that interface. 00:05:53.270 --> 00:05:55.070 Here's an arrow. 00:05:55.070 --> 00:05:56.910 And right now the arrow is facing the right. 00:05:56.910 --> 00:06:00.410 But if I wanted to go up, then I'm going to rotate it instead of 90 degrees, 00:06:00.410 --> 00:06:02.150 let's set it to 0 degrees. 00:06:02.150 --> 00:06:04.970 That's going to be an arrow that's facing up. 00:06:04.970 --> 00:06:10.400 And if I want a button that lets the duck go down, let's add an arrow. 00:06:10.400 --> 00:06:13.530 And this time set it to 180 degrees. 00:06:13.530 --> 00:06:16.890 And now the arrow is facing down. 00:06:16.890 --> 00:06:18.680 So now I have two arrows. 00:06:18.680 --> 00:06:22.140 But clicking these arrows doesn't achieve anything. 00:06:22.140 --> 00:06:25.790 They just do nothing right now because I haven't added any code to them. 00:06:25.790 --> 00:06:27.200 But I could. 00:06:27.200 --> 00:06:32.960 Let me add an event to the up arrow that says when this sprite is clicked, 00:06:32.960 --> 00:06:38.480 when I click on the up arrow, well then let's broadcast a message. 00:06:38.480 --> 00:06:41.210 And the message is going to be up. 00:06:41.210 --> 00:06:43.670 That's the direction you should move. 00:06:43.670 --> 00:06:46.320 Now let's choose the down arrow. 00:06:46.320 --> 00:06:49.280 This time when the sprite is clicked, let's 00:06:49.280 --> 00:06:53.180 broadcast a message not up, but this time a new message. 00:06:53.180 --> 00:06:55.530 And the message is going to be down. 00:06:55.530 --> 00:06:58.700 So now the up arrow is broadcasting a message that says up. 00:06:58.700 --> 00:07:02.030 The down arrow is broadcasting a message that says down. 00:07:02.030 --> 00:07:05.120 And now I'll have the duck respond to those broadcasts. 00:07:05.120 --> 00:07:10.010 When the duck receives the up message, well then 00:07:10.010 --> 00:07:16.220 let's have the duck change its y value by 10 going upward in direction. 00:07:16.220 --> 00:07:22.340 And likewise under Events, when the duck receives the down broadcast message, 00:07:22.340 --> 00:07:28.010 then we're going to change the y value by negative 10. 00:07:28.010 --> 00:07:31.430 And now these arrows, these sprites on the screen, 00:07:31.430 --> 00:07:33.230 are controlling the behavior of the duck. 00:07:33.230 --> 00:07:36.470 If I click the up arrow, the duck moves up. 00:07:36.470 --> 00:07:39.470 And if I click the down arrow, the duck moves down. 00:07:39.470 --> 00:07:41.540 And they're doing that because of broadcasting. 00:07:41.540 --> 00:07:44.720 When I click on the arrows, those arrows are themselves 00:07:44.720 --> 00:07:48.020 sprites that are saying move up or move down. 00:07:48.020 --> 00:07:49.970 They're broadcasting some message. 00:07:49.970 --> 00:07:55.190 And the duck in turn is then responding to those messages. 00:07:55.190 --> 00:07:59.930 And it doesn't just have to be sprites that are broadcasting messages. 00:07:59.930 --> 00:08:03.350 The stage, the background can broadcast messages too. 00:08:03.350 --> 00:08:05.090 I'll show you an example of that. 00:08:05.090 --> 00:08:06.860 I'll delete all of these sprites for now. 00:08:06.860 --> 00:08:08.270 Let's add a backdrop. 00:08:08.270 --> 00:08:11.270 And let's go back to our underwater backdrop. 00:08:11.270 --> 00:08:13.850 And let's bring our fish back. 00:08:13.850 --> 00:08:20.270 So I'll add a new sprite and add back the fish. 00:08:20.270 --> 00:08:23.540 And now what I would like to do is in the backdrop, 00:08:23.540 --> 00:08:26.150 I'll click on the backdrop, add some code here, 00:08:26.150 --> 00:08:31.160 I'll say whenever the stage is clicked, when stage clicked, 00:08:31.160 --> 00:08:34.669 let's now broadcast a message. 00:08:34.669 --> 00:08:38.150 And the message is going to be visit. 00:08:38.150 --> 00:08:44.870 I would like the fish to visit wherever I click on the stage. 00:08:44.870 --> 00:08:49.000 And now for the fish whenever it receives the visit message, 00:08:49.000 --> 00:08:53.530 let's have the fish point towards the mouse pointer 00:08:53.530 --> 00:08:59.060 and then take one second to glide to the mouse pointer. 00:08:59.060 --> 00:09:00.160 So now I press the flag. 00:09:00.160 --> 00:09:01.550 At first, nothing happens. 00:09:01.550 --> 00:09:06.400 But if I choose a location and then click, the fish goes there. 00:09:06.400 --> 00:09:11.380 I choose the location and click, and the fish visits wherever I happen to click. 00:09:11.380 --> 00:09:12.130 I click over here. 00:09:12.130 --> 00:09:13.310 The fish goes there. 00:09:13.310 --> 00:09:17.170 And every time when I click, the backdrop is broadcasting a message. 00:09:17.170 --> 00:09:19.990 The stage is broadcasting this visit message 00:09:19.990 --> 00:09:23.380 and the fish is now receiving that visit message 00:09:23.380 --> 00:09:26.320 and doing something in response, pointing towards the mouse pointer 00:09:26.320 --> 00:09:27.560 and gliding there. 00:09:27.560 --> 00:09:31.390 So broadcasting allows multiple different parts of our Scratch project 00:09:31.390 --> 00:09:36.370 to communicate with each other to decide when something should happen. 00:09:36.370 --> 00:09:40.330 And that's one very powerful, very useful feature within Scratch. 00:09:40.330 --> 00:09:44.470 Another feature that can be useful, and for this I'll get rid of the backdrop, 00:09:44.470 --> 00:09:47.320 I'll go back to the default white backdrop, 00:09:47.320 --> 00:09:50.650 is the ability to clone a sprite. 00:09:50.650 --> 00:09:53.350 If I have one copy of a sprite oftentimes in a game 00:09:53.350 --> 00:09:56.320 or in some sort of other animation, I might not just one 00:09:56.320 --> 00:10:00.130 copy of a sprite on the stage, but I might want multiple copies 00:10:00.130 --> 00:10:03.020 of that sprite on the stage as well. 00:10:03.020 --> 00:10:04.270 So let's add a sprite. 00:10:04.270 --> 00:10:08.320 Let me search for the star and let's grab the star. 00:10:08.320 --> 00:10:10.450 And maybe what I'd like to happen is to not just 00:10:10.450 --> 00:10:15.890 have one star but to have multiple stars inside of my project. 00:10:15.890 --> 00:10:18.670 So let's add some code here. 00:10:18.670 --> 00:10:23.740 I'll say when this sprite is clicked, when I click on the star, 00:10:23.740 --> 00:10:30.550 I am going to, and this is under Control, create a clone of myself. 00:10:30.550 --> 00:10:34.000 When the star is clicked, we're going to create a clone of the star. 00:10:34.000 --> 00:10:36.550 And that new clone is going to be another star that 00:10:36.550 --> 00:10:39.170 can behave on its own. 00:10:39.170 --> 00:10:40.360 Now I'll add this new event. 00:10:40.360 --> 00:10:44.230 When I start as a clone, what should this clone star do? 00:10:44.230 --> 00:10:50.270 Well, let's have the cloned star just glide one second to a random position. 00:10:50.270 --> 00:10:52.730 So I have this star, and watch what happens. 00:10:52.730 --> 00:10:58.490 Every time I click on the star, the star creates a new clone. 00:10:58.490 --> 00:11:00.600 Every time I click, a new clone is created. 00:11:00.600 --> 00:11:03.350 And when the new star starts as a clone, it's 00:11:03.350 --> 00:11:05.720 going to glide to a random position. 00:11:05.720 --> 00:11:10.880 Every time I clone a star, you'll see we create a duplicate event 00:11:10.880 --> 00:11:13.950 and it ends up going to a random position. 00:11:13.950 --> 00:11:17.930 So if I want multiple of a particular sprite that appear on the stage, 00:11:17.930 --> 00:11:19.350 cloning is a great way to do that. 00:11:19.350 --> 00:11:21.920 We can create multiple copies of a sprite 00:11:21.920 --> 00:11:27.470 and then decide how it is that those clones should ultimately behave. 00:11:27.470 --> 00:11:30.140 So now I'll go ahead and get rid of all those clones 00:11:30.140 --> 00:11:34.870 just by deleting the sprite and clearing the screen. 00:11:34.870 --> 00:11:37.870 Now we've seen a lot of features that Scratch has to offer. 00:11:37.870 --> 00:11:40.030 We've seen functions and we've seen events. 00:11:40.030 --> 00:11:43.420 We've seen variable, loops and conditions, and now the ability 00:11:43.420 --> 00:11:45.940 to broadcast messages and clone sprites. 00:11:45.940 --> 00:11:48.430 Let's take all of those ideas now and put them 00:11:48.430 --> 00:11:51.100 together inside of a fully complete game to show you 00:11:51.100 --> 00:11:55.810 how you could go about building a more complex project within Scratch. 00:11:55.810 --> 00:11:58.010 And what characters should I use in the game? 00:11:58.010 --> 00:12:02.380 Let's start and just start building this game one piece at a time. 00:12:02.380 --> 00:12:05.800 Well, let's start by using the cat. 00:12:05.800 --> 00:12:08.780 Sort of the classic default sprite character. 00:12:08.780 --> 00:12:12.140 And let's have the cat have some objective. 00:12:12.140 --> 00:12:13.765 What is the cat trying to do? 00:12:13.765 --> 00:12:15.640 Well, I can just scroll through these sprites 00:12:15.640 --> 00:12:17.140 and look for what seems interesting. 00:12:17.140 --> 00:12:18.880 Here are the crystals. 00:12:18.880 --> 00:12:23.177 Let's have the cat try to catch as many crystals as it can. 00:12:23.177 --> 00:12:24.760 And what are the crystals going to do? 00:12:24.760 --> 00:12:26.410 Well, just thinking about what I want the game to do, 00:12:26.410 --> 00:12:28.600 I could decide how I would like the game to work. 00:12:28.600 --> 00:12:31.480 And maybe the crystals are going to fall from the sky 00:12:31.480 --> 00:12:35.780 and the cat has to try to catch the crystals before they hit the ground. 00:12:35.780 --> 00:12:37.870 So that's ultimately what I would like to happen. 00:12:37.870 --> 00:12:41.170 The cat's going to try and catch crystals before they hit the ground. 00:12:41.170 --> 00:12:41.990 I have a cat. 00:12:41.990 --> 00:12:43.120 I have a crystal. 00:12:43.120 --> 00:12:48.260 But now I need to add code to figure out how to make that work. 00:12:48.260 --> 00:12:50.060 Well, what do I need? 00:12:50.060 --> 00:12:52.540 Well, first I need some way for the cat to move around. 00:12:52.540 --> 00:12:55.060 And I'll have the cat move around with the arrow keys. 00:12:55.060 --> 00:12:59.240 So let's add an event. 00:12:59.240 --> 00:13:06.920 When the left arrow is clicked, we're going to change x by negative 10. 00:13:06.920 --> 00:13:09.300 And I'll duplicate this as well. 00:13:09.300 --> 00:13:14.370 And I'll say that when the right arrow is clicked, let's change x by 10. 00:13:14.370 --> 00:13:16.370 So now I have the ability to move the cat. 00:13:16.370 --> 00:13:20.362 It can move around to the left and it can move around to the right. 00:13:20.362 --> 00:13:21.320 And that's what I want. 00:13:21.320 --> 00:13:24.163 As the crystals are falling, the cat's going 00:13:24.163 --> 00:13:26.330 to move left and right to try and catch the crystal. 00:13:26.330 --> 00:13:29.288 I don't need the cat to move up and down, because really the cat's only 00:13:29.288 --> 00:13:34.370 going to exist along this bottom portion of the stage here. 00:13:34.370 --> 00:13:36.780 And now when the game starts, what should happen? 00:13:36.780 --> 00:13:40.190 Well, the game's going to start when the flag is clicked. 00:13:40.190 --> 00:13:43.280 And when the flag is clicked, I'd like for the cat 00:13:43.280 --> 00:13:47.070 to go back to the middle of the stage just as a starting point. 00:13:47.070 --> 00:13:50.480 So I'll have the cat first go to 0 for x. 00:13:50.480 --> 00:13:53.120 And we'll go negative 125 for y. 00:13:53.120 --> 00:13:58.820 So this now is the starting point for the cat at 0 for x, negative 125 for y. 00:13:58.820 --> 00:14:04.310 And from there, I can use the arrow keys to move back and forth. 00:14:04.310 --> 00:14:06.740 And because it's a game, it's probably helpful for me 00:14:06.740 --> 00:14:09.360 to tell the user how to play the game. 00:14:09.360 --> 00:14:13.850 So let's add a message for the cat to say. 00:14:13.850 --> 00:14:18.680 And the cat's going to say something like, catch the crystals 00:14:18.680 --> 00:14:23.525 without letting them hit the ground. 00:14:23.525 --> 00:14:24.650 Those are the instructions. 00:14:24.650 --> 00:14:27.320 Catch the crystals without letting them hit the ground. 00:14:27.320 --> 00:14:29.480 And I'll have the cat say that for let's say 00:14:29.480 --> 00:14:32.480 four seconds to give the user enough time to see that message 00:14:32.480 --> 00:14:34.740 and then respond to it. 00:14:34.740 --> 00:14:37.190 So we're going to start. 00:14:37.190 --> 00:14:37.850 The cat speaks. 00:14:37.850 --> 00:14:40.250 Catch the crystals without letting them hit the ground. 00:14:40.250 --> 00:14:43.260 And now we have the ability to move around. 00:14:43.260 --> 00:14:45.210 That's a pretty good start. 00:14:45.210 --> 00:14:48.613 Now let's see if we can do something with this crystal. 00:14:48.613 --> 00:14:51.530 Now, one thing you might have noticed is that when I started the game, 00:14:51.530 --> 00:14:54.350 the crystal's already just hanging around here. 00:14:54.350 --> 00:14:57.187 Maybe I'd like to not show the crystal until the cat's 00:14:57.187 --> 00:14:58.520 done giving in the instructions. 00:14:58.520 --> 00:15:02.420 I want the cat to give the instructions and then the crystal can show itself 00:15:02.420 --> 00:15:04.380 and we can start playing the game. 00:15:04.380 --> 00:15:05.670 How would I do that? 00:15:05.670 --> 00:15:08.900 Well, I would say for the crystal when the flag is clicked, 00:15:08.900 --> 00:15:15.710 when this program starts running, let's go under Looks and let's hide. 00:15:15.710 --> 00:15:19.580 So initially when I start the program, all that we see is the cat. 00:15:19.580 --> 00:15:21.630 The cat gives the instructions. 00:15:21.630 --> 00:15:24.110 And now that the instructions are over, I 00:15:24.110 --> 00:15:27.650 would like the cat to somehow signal to the crystal, all right, it's OK for you 00:15:27.650 --> 00:15:32.500 to create a crystal to now start falling from the sky. 00:15:32.500 --> 00:15:34.250 And maybe eventually in my game, I'm going 00:15:34.250 --> 00:15:37.950 to have multiple crystals moving around, but we'll start with just one. 00:15:37.950 --> 00:15:39.450 And what is this going to look like? 00:15:39.450 --> 00:15:43.910 How does the cat signal to the crystal that we're done giving instructions? 00:15:43.910 --> 00:15:46.790 It's time for the crystal to now appear. 00:15:46.790 --> 00:15:48.140 Well, we can use broadcasting. 00:15:48.140 --> 00:15:51.170 Remember that broadcasting allows one sprite to send 00:15:51.170 --> 00:15:54.710 a message to another sprite to indicate that it's now their turn 00:15:54.710 --> 00:15:59.420 to do something or say something or appear on the stage. 00:15:59.420 --> 00:16:03.170 So I'll go to Events and we'll broadcast a message. 00:16:03.170 --> 00:16:09.900 And the message will be a new message just called begin. 00:16:09.900 --> 00:16:13.150 Begin is going to mean, all right, now is the time to actually begin the game. 00:16:13.150 --> 00:16:15.050 We're done giving the instructions. 00:16:15.050 --> 00:16:20.420 And now the crystal needs to respond to that begin message. 00:16:20.420 --> 00:16:24.588 So when I receive begin, now the crystal can decide what to do. 00:16:24.588 --> 00:16:26.380 But as I'm thinking ahead to the way that I 00:16:26.380 --> 00:16:28.540 want to organize the code in this game, I'm 00:16:28.540 --> 00:16:31.480 realizing that I might not just want one crystal. 00:16:31.480 --> 00:16:33.700 I might not just have one crystal that's falling, 00:16:33.700 --> 00:16:36.100 but I probably want to have multiple crystals falling. 00:16:36.100 --> 00:16:39.040 Once one crystal falls, I want another crystal to appear, 00:16:39.040 --> 00:16:42.890 and maybe there are eventually going to be multiple crystals at the same time. 00:16:42.890 --> 00:16:46.090 And so thinking ahead, when I receive begin, 00:16:46.090 --> 00:16:50.890 let's go ahead and create a clone of the crystal. 00:16:50.890 --> 00:16:52.600 Just create a brand new crystal. 00:16:52.600 --> 00:16:55.120 And every time I create a clone of a crystal, 00:16:55.120 --> 00:16:59.960 I'll get a new crystal that's going to start falling from the sky. 00:16:59.960 --> 00:17:01.330 And so what should happen? 00:17:01.330 --> 00:17:09.260 When the crystal starts as a clone, let's start now by showing the crystal. 00:17:09.260 --> 00:17:10.329 So how is this working? 00:17:10.329 --> 00:17:12.640 At first the crystal is going to hide itself. 00:17:12.640 --> 00:17:15.010 But once we receive the begin message from the cat, 00:17:15.010 --> 00:17:18.579 once the cat is done giving the instructions and the cat says begin, 00:17:18.579 --> 00:17:21.579 we're going to create a new clone of the crystal. 00:17:21.579 --> 00:17:25.670 And when the crystal starts as a clone, the crystal will show itself. 00:17:25.670 --> 00:17:28.780 So we see the instructions from the cat. 00:17:28.780 --> 00:17:33.410 And then after the instructions are over, we now see the crystal up here. 00:17:33.410 --> 00:17:35.900 We'd like for that crystal to go somewhere. 00:17:35.900 --> 00:17:38.708 So let's have the crystal go to-- 00:17:38.708 --> 00:17:40.000 we'll have it centered for now. 00:17:40.000 --> 00:17:41.590 We'll have it centered at 0. 00:17:41.590 --> 00:17:43.240 And y should be pretty big. 00:17:43.240 --> 00:17:45.760 I'll make it 160 just to make it a little taller. 00:17:45.760 --> 00:17:48.520 And so now the cat gives the instructions. 00:17:48.520 --> 00:17:51.370 And after the instructions are over, the crystal 00:17:51.370 --> 00:17:54.730 appears right at the top up high at the top of the screen. 00:17:54.730 --> 00:17:57.130 But now I'd like the crystal to start falling. 00:17:57.130 --> 00:17:58.460 It's up in the sky. 00:17:58.460 --> 00:18:00.760 Now I need to get it to move down. 00:18:00.760 --> 00:18:04.600 Well, I can move down just by changing the y value. 00:18:04.600 --> 00:18:08.140 If I change the y value by a negative number, like negative 1, 00:18:08.140 --> 00:18:10.990 or if I wanted a little faster, negative 2 for example, 00:18:10.990 --> 00:18:14.050 that's going to cause the crystal to move down. 00:18:14.050 --> 00:18:18.167 But now I don't just want the crystal to move down once, 00:18:18.167 --> 00:18:20.500 but I want the crystal to move down over and over again, 00:18:20.500 --> 00:18:24.730 to move down a little bit and then keep moving down again and again and again. 00:18:24.730 --> 00:18:31.790 So I'll put all of that under control inside of a forever loop. 00:18:31.790 --> 00:18:33.370 So now here's what's happening. 00:18:33.370 --> 00:18:36.790 When we start a new crystal, the crystal is going to show itself. 00:18:36.790 --> 00:18:39.040 It's going to go up to the top of the screen, 00:18:39.040 --> 00:18:42.430 and then forever it's just going to start falling. 00:18:42.430 --> 00:18:44.500 So now we can see what happens. 00:18:44.500 --> 00:18:46.450 The cat gives the instructions. 00:18:46.450 --> 00:18:52.050 The crystal appears, and the crystal now is falling. 00:18:52.050 --> 00:18:54.230 And so this is often what the development process 00:18:54.230 --> 00:18:55.130 is like for the game. 00:18:55.130 --> 00:18:57.260 It's not that you're going to write all of the blocks 00:18:57.260 --> 00:18:59.870 and put together all the different sprites for the entire game 00:18:59.870 --> 00:19:01.903 and then run it and see the finished product. 00:19:01.903 --> 00:19:04.320 It's that you're going to build it a little bit at a time. 00:19:04.320 --> 00:19:05.300 I need the cat to move. 00:19:05.300 --> 00:19:07.400 I need the cat to speak some instructions. 00:19:07.400 --> 00:19:08.823 I need the crystal to appear. 00:19:08.823 --> 00:19:10.490 Now I need the crystal to start falling. 00:19:10.490 --> 00:19:12.980 And after each time, you add just a few blocks 00:19:12.980 --> 00:19:14.660 to change the behavior a little bit. 00:19:14.660 --> 00:19:16.638 You can run the project, see what happens, 00:19:16.638 --> 00:19:18.680 and if you need to tinker with some of the blocks 00:19:18.680 --> 00:19:21.650 to make it work if it didn't work the way you wanted it to work. 00:19:21.650 --> 00:19:25.620 And we're now just building this game slowly one piece at a time. 00:19:25.620 --> 00:19:26.780 So what do we have so far? 00:19:26.780 --> 00:19:28.310 We have a cat that can move around. 00:19:28.310 --> 00:19:29.250 That works. 00:19:29.250 --> 00:19:32.810 We have a crystal that appears from the sky and starts to fall. 00:19:32.810 --> 00:19:36.950 But right now nothing yet happens once the cat catches the crystal. 00:19:36.950 --> 00:19:39.620 Once the crystal touches the cat. 00:19:39.620 --> 00:19:40.860 So let's add that. 00:19:40.860 --> 00:19:42.540 How can we do that? 00:19:42.540 --> 00:19:44.630 Well, that sounds like a condition. 00:19:44.630 --> 00:19:48.770 We're checking if the crystal is touching the cat. 00:19:48.770 --> 00:19:52.700 So let's add an if statement into the loop. 00:19:52.700 --> 00:19:58.790 And we'll say if we're touching not the mouse pointer but the cat. 00:19:58.790 --> 00:20:03.060 If the crystal is touching the cat, well then what should happen? 00:20:03.060 --> 00:20:04.760 Well, I want to somehow keep score. 00:20:04.760 --> 00:20:08.810 I want to keep track of how many crystals has the cat caught. 00:20:08.810 --> 00:20:11.060 And so to do that I need to store information 00:20:11.060 --> 00:20:12.860 somewhere inside of my Scratch project. 00:20:12.860 --> 00:20:15.710 Sounds like we need a variable, some variable that's 00:20:15.710 --> 00:20:18.570 going to keep track of this information for us. 00:20:18.570 --> 00:20:19.760 So let's go to Variable. 00:20:19.760 --> 00:20:21.230 Let's make a new variable. 00:20:21.230 --> 00:20:24.080 And I will call this variable catches. 00:20:24.080 --> 00:20:25.580 That's going to represent the score. 00:20:25.580 --> 00:20:30.710 It's how many catches the cat has made, how many crystals the cat has caught. 00:20:30.710 --> 00:20:33.410 You'll notice the catches right now is 0. 00:20:33.410 --> 00:20:38.330 And I would like to make sure that when the game first begins that we always 00:20:38.330 --> 00:20:41.480 reset the number of catches back to 0. 00:20:41.480 --> 00:20:44.298 So inside the cat, you'll notice that when the flag is clicked 00:20:44.298 --> 00:20:45.590 we're doing a lot of resetting. 00:20:45.590 --> 00:20:49.340 We're going to this original x equals 0 position to center 00:20:49.340 --> 00:20:50.930 the cat at the beginning. 00:20:50.930 --> 00:20:54.680 At the same time, let me set catches to 0 at the beginning. 00:20:54.680 --> 00:20:58.310 Because if I accumulate a score and I play the game again, 00:20:58.310 --> 00:20:59.690 I want to reset the score. 00:20:59.690 --> 00:21:04.670 I want the score to go back to 0, and then I can start adding to the score. 00:21:04.670 --> 00:21:06.170 How do I add to the score? 00:21:06.170 --> 00:21:08.720 Well, that's going to happen in the crystal sprite 00:21:08.720 --> 00:21:10.550 when it's touching the cat. 00:21:10.550 --> 00:21:14.120 If we're touching the cat, we have now caught one additional crystal. 00:21:14.120 --> 00:21:16.940 Let's change catches by one. 00:21:16.940 --> 00:21:19.290 And now what should happen? 00:21:19.290 --> 00:21:21.740 Well, now once the cat has caught a crystal, 00:21:21.740 --> 00:21:26.510 let's create a new crystal for the cat to try to catch. 00:21:26.510 --> 00:21:30.140 To do that, I can go back to control. 00:21:30.140 --> 00:21:32.180 And I can create another clone. 00:21:32.180 --> 00:21:36.140 Every time I create a clone, let's go ahead and stop this for now, 00:21:36.140 --> 00:21:40.430 every time I create a new clone, that is going to create a new crystal. 00:21:40.430 --> 00:21:42.680 And whenever we start as a clone, that crystal 00:21:42.680 --> 00:21:46.400 is going to go to the top of the screen and it's going to start to fall. 00:21:46.400 --> 00:21:51.950 And after I create a clone, let's go ahead and delete the current clone. 00:21:51.950 --> 00:21:53.070 So what's going on here? 00:21:53.070 --> 00:21:54.860 Why have I added these blocks into place? 00:21:54.860 --> 00:21:57.485 Well, when we're touching the cat, that's one additional catch. 00:21:57.485 --> 00:21:59.780 We're updating the variable, changing catches by one. 00:21:59.780 --> 00:22:05.810 And creating a new clone, because once the cat has caught one crystal, 00:22:05.810 --> 00:22:08.900 I'd like for a new crystal to appear at the top of the screen. 00:22:08.900 --> 00:22:12.080 But then finally, I'm deleting this clone. 00:22:12.080 --> 00:22:14.667 Once the cat has caught the crystal, I'm just 00:22:14.667 --> 00:22:17.250 going to delete that crystal, because I don't need it anymore. 00:22:17.250 --> 00:22:22.080 I have a new crystal that's going to be falling from the top of the screen 00:22:22.080 --> 00:22:24.200 instead. 00:22:24.200 --> 00:22:26.666 And so now let's try this program. 00:22:26.666 --> 00:22:28.790 I'll press the flag. 00:22:28.790 --> 00:22:32.150 The cat gives some instructions, catches, resets back to 0, 00:22:32.150 --> 00:22:34.490 and we see the crystal falling. 00:22:34.490 --> 00:22:37.730 And when the cat catches it, notice the catches goes up by one. 00:22:37.730 --> 00:22:40.095 The score has increased and a new crystal appears. 00:22:40.095 --> 00:22:41.720 And you'll notice this keeps happening. 00:22:41.720 --> 00:22:42.470 It's in a loop. 00:22:42.470 --> 00:22:46.370 Every time a crystal is caught, our score goes up by one. 00:22:46.370 --> 00:22:51.170 And the crystal creates a new crystal that appears at the top of the screen. 00:22:51.170 --> 00:22:56.060 And then the crystal that the cat caught disappears and we no longer see it. 00:22:56.060 --> 00:22:58.850 So we're just seeing this flow of crystals appear one at a time. 00:22:58.850 --> 00:23:02.420 We're seeing our variable update and increase by one every time 00:23:02.420 --> 00:23:03.800 the cat catches a crystal. 00:23:03.800 --> 00:23:07.020 And ultimately, this seems to now work pretty well. 00:23:07.020 --> 00:23:10.455 The problem that I see is that the game is a little bit too easy. 00:23:10.455 --> 00:23:12.080 I'm not even at the computer right now. 00:23:12.080 --> 00:23:15.020 I'm not moving the cat at all and the crystal is just 00:23:15.020 --> 00:23:17.390 appearing right on top of the cat and the cat 00:23:17.390 --> 00:23:20.310 is catching it every single time. 00:23:20.310 --> 00:23:21.920 So that's maybe not quite what I want. 00:23:21.920 --> 00:23:25.290 What I'd like to do is introduce a bit of randomness into a game. 00:23:25.290 --> 00:23:27.590 And this is a common property of games, randomness, 00:23:27.590 --> 00:23:30.440 because you don't want the game to be exactly the same every time. 00:23:30.440 --> 00:23:32.900 You want some different choices to be made sometimes, 00:23:32.900 --> 00:23:35.210 a little bit of unpredictability so that the user 00:23:35.210 --> 00:23:37.880 is going to have to respond to whatever they see. 00:23:37.880 --> 00:23:40.850 And in this case, the unpredictability that I want 00:23:40.850 --> 00:23:43.340 is the x value of the crystal. 00:23:43.340 --> 00:23:45.950 That right now the x value of the crystal is always 0. 00:23:45.950 --> 00:23:49.190 It's always going to x equals 0. 00:23:49.190 --> 00:23:51.050 And because of that, the crystal is always 00:23:51.050 --> 00:23:53.210 just immediately on top of the cat. 00:23:53.210 --> 00:23:57.020 What I'd like to happen is for the crystal to sometimes be on the left 00:23:57.020 --> 00:23:58.400 and sometimes be on the right. 00:23:58.400 --> 00:24:00.920 That way I have to move around rather than just keep 00:24:00.920 --> 00:24:03.930 increasing my score by doing nothing. 00:24:03.930 --> 00:24:05.610 So let's go ahead and do that. 00:24:05.610 --> 00:24:09.080 I will come over here and stop my project. 00:24:09.080 --> 00:24:12.290 And instead of going to x equals 0 every time 00:24:12.290 --> 00:24:15.200 the crystal starts, let's add some randomness. 00:24:15.200 --> 00:24:16.550 I go under Operators. 00:24:16.550 --> 00:24:18.290 Here's pick random. 00:24:18.290 --> 00:24:21.150 And far left, that's going to be a big negative number. 00:24:21.150 --> 00:24:24.410 So we'll go from negative 200 to the far right. 00:24:24.410 --> 00:24:26.210 That's going to be a big positive number. 00:24:26.210 --> 00:24:27.710 I'll make it positive 200. 00:24:27.710 --> 00:24:30.960 But you could play around with those values for whatever you'd like. 00:24:30.960 --> 00:24:36.020 And now when I start the game, the score resets and notice 00:24:36.020 --> 00:24:38.810 that the crystal is going to appear. 00:24:38.810 --> 00:24:42.140 This time it was kind of centered, but maybe it won't be that way every time. 00:24:42.140 --> 00:24:45.260 Now the crystal's off to the right, and I have to move to the right 00:24:45.260 --> 00:24:47.430 in order to catch it. 00:24:47.430 --> 00:24:49.670 And every time I catch the crystal, the crystal 00:24:49.670 --> 00:24:54.650 is going to generate a new random number between negative 200 and 200. 00:24:54.650 --> 00:24:58.140 And that's going to tell me where I need to go in order to catch the crystal. 00:24:58.140 --> 00:25:02.030 This is a much more interesting game than when the crystal was just always 00:25:02.030 --> 00:25:05.790 appearing in the same spot every time. 00:25:05.790 --> 00:25:08.270 So this is definitely an improvement. 00:25:08.270 --> 00:25:10.700 And now I'm curious, what happens if I miss? 00:25:10.700 --> 00:25:14.900 If I miss the crystal altogether and just let the crystal fall. 00:25:14.900 --> 00:25:17.840 All right, the crystal hits the bottom of the screen 00:25:17.840 --> 00:25:20.570 and now the game is kind of stuck. 00:25:20.570 --> 00:25:23.930 What I'd like to do is add some code that can handle this situation. 00:25:23.930 --> 00:25:27.380 What happens if the crystal ever touches the edge of the screen 00:25:27.380 --> 00:25:29.400 and I didn't catch it? 00:25:29.400 --> 00:25:31.260 What should happen? 00:25:31.260 --> 00:25:34.460 Well, let's add another condition. 00:25:34.460 --> 00:25:37.130 I'll add a condition to the bottom here underneath the loop. 00:25:37.130 --> 00:25:40.040 Not if we're touching the cat, but this time 00:25:40.040 --> 00:25:43.430 if we're touching the edge of the screen. 00:25:43.430 --> 00:25:46.280 If ever the crystal makes it all the way down to the bottom 00:25:46.280 --> 00:25:50.820 and now it's touching the edge of the screen, what should we do? 00:25:50.820 --> 00:25:51.710 Well, we can decide. 00:25:51.710 --> 00:25:53.030 We haven't really talked about what's going 00:25:53.030 --> 00:25:54.530 to happen in the game at this point. 00:25:54.530 --> 00:25:56.840 Maybe the game's over right away and we're just done. 00:25:56.840 --> 00:25:59.150 Or maybe you get a couple of chances. 00:25:59.150 --> 00:26:00.560 You're given like three misses. 00:26:00.560 --> 00:26:02.900 And after three misses, then you lose the game. 00:26:02.900 --> 00:26:04.640 And let's try and do that. 00:26:04.640 --> 00:26:07.640 In order to make that happen, I need to keep track of how many misses 00:26:07.640 --> 00:26:09.300 there have been so far. 00:26:09.300 --> 00:26:14.480 So I'm going to go to variables and create a new variable called misses. 00:26:14.480 --> 00:26:18.860 How many times has the cat now missed the crystal? 00:26:18.860 --> 00:26:21.200 And just as in the beginning of the cat, we 00:26:21.200 --> 00:26:25.370 set catches to 0 to reset the value of catches at the beginning of the game, 00:26:25.370 --> 00:26:28.430 let's also now set misses to 0. 00:26:28.430 --> 00:26:31.110 When the game first begins, you haven't missed any yet. 00:26:31.110 --> 00:26:32.810 So let's reset it back to 0. 00:26:32.810 --> 00:26:37.940 That way any previous progress in the game is erased. 00:26:37.940 --> 00:26:41.600 But now if ever we're touching the edge, let's go ahead 00:26:41.600 --> 00:26:46.280 and change the number of misses by one. 00:26:46.280 --> 00:26:49.490 And at that point, we can do much the same thing as we were doing before. 00:26:49.490 --> 00:26:53.432 We're going to create a new crystal by creating a clone. 00:26:53.432 --> 00:26:55.640 Let's go ahead and stop this for now, otherwise we're 00:26:55.640 --> 00:26:57.230 going to get a lot of clones. 00:26:57.230 --> 00:27:02.925 But then let's also delete this clone after that. 00:27:02.925 --> 00:27:06.050 So when we're touching the edge, we're going to change the number of misses 00:27:06.050 --> 00:27:06.550 by one. 00:27:06.550 --> 00:27:07.970 We now have one additional miss. 00:27:07.970 --> 00:27:10.340 We're going to create a new crystal, and then we're 00:27:10.340 --> 00:27:13.760 going to delete the clone to say we're done with this crystal. 00:27:13.760 --> 00:27:15.750 We've now created a new one. 00:27:15.750 --> 00:27:19.220 So now we'll see how the game behaves. 00:27:19.220 --> 00:27:20.450 The crystals are falling. 00:27:20.450 --> 00:27:23.278 I can try to catch them. 00:27:23.278 --> 00:27:24.320 That's one that I caught. 00:27:24.320 --> 00:27:27.110 I'll catch one more. 00:27:27.110 --> 00:27:31.175 Now let me miss this one and see what happens. 00:27:31.175 --> 00:27:34.050 The crystal is going to hit the bottom of the screen and I missed it. 00:27:34.050 --> 00:27:36.500 You notice my misses goes up by one. 00:27:36.500 --> 00:27:39.590 If I miss this one as well, misses goes up again. 00:27:39.590 --> 00:27:42.440 And now I effectively have two variables, 00:27:42.440 --> 00:27:47.070 one keeping track of how many times I've caught the crystal and one keeping 00:27:47.070 --> 00:27:49.070 track of how many times I've missed the crystal. 00:27:49.070 --> 00:27:50.778 And there seems to be no limit right now. 00:27:50.778 --> 00:27:54.050 Misses can just keep going up and up and up every time I miss the crystal. 00:27:54.050 --> 00:27:58.400 What I'd like to do is do something once I miss three of them. 00:27:58.400 --> 00:28:02.160 Once I miss three, I want the game to be over. 00:28:02.160 --> 00:28:05.090 So let's add a condition to check for that. 00:28:05.090 --> 00:28:06.590 I'm going to take this if condition. 00:28:06.590 --> 00:28:09.110 I'll build it out here for now and then I'll drag it in, 00:28:09.110 --> 00:28:11.060 just to keep it separate for now. 00:28:11.060 --> 00:28:15.590 But I'm going to say if the number of misses is equal to three, 00:28:15.590 --> 00:28:19.220 so equals is an operator, and I'm going to say if the number of misses 00:28:19.220 --> 00:28:22.350 are now equal to three, well what should we do? 00:28:22.350 --> 00:28:24.440 Well, the game is now going to be over. 00:28:24.440 --> 00:28:28.670 So I'm going to eventually delete this clone, because I no longer need 00:28:28.670 --> 00:28:30.930 the crystal once the game is over. 00:28:30.930 --> 00:28:34.250 But at this point as well, I need some way 00:28:34.250 --> 00:28:37.550 to signal to the rest of the program that the game is over. 00:28:37.550 --> 00:28:39.350 I need the cat to know the game is over. 00:28:39.350 --> 00:28:42.590 Because maybe the cat is now going to report what my score was. 00:28:42.590 --> 00:28:44.390 What is my score at the end of the game? 00:28:44.390 --> 00:28:46.760 How many crystals did I catch? 00:28:46.760 --> 00:28:51.068 So how can the crystal tell the cat that something has happened in the project? 00:28:51.068 --> 00:28:52.610 Well, that's going to be a broadcast. 00:28:52.610 --> 00:28:56.750 Broadcast as a way of sending messages, again, between sprites. 00:28:56.750 --> 00:28:58.590 I'll broadcast a message. 00:28:58.590 --> 00:29:02.720 But instead of begin, the message is going to be game over. 00:29:02.720 --> 00:29:03.800 The game is over. 00:29:03.800 --> 00:29:06.080 Let's make sure the cat knows that. 00:29:06.080 --> 00:29:12.740 And let's drag that into this logic right after we change misses by one. 00:29:12.740 --> 00:29:15.350 So we increase the number of misses, and then we check. 00:29:15.350 --> 00:29:17.270 Is our number of misses equal to three? 00:29:17.270 --> 00:29:20.060 If so we broadcast that the game is over. 00:29:20.060 --> 00:29:27.050 And now last step here, in the cat I need to respond to that event. 00:29:27.050 --> 00:29:31.770 When I receive game over, what should happen? 00:29:31.770 --> 00:29:35.780 Well, when I receive game over, let's go ahead and say the score. 00:29:35.780 --> 00:29:39.500 Let's say-- and I could just say the score directly. 00:29:39.500 --> 00:29:42.200 But to make it a little nicer, I'll join together two words. 00:29:42.200 --> 00:29:47.810 I'll say your score is and then a space and then 00:29:47.810 --> 00:29:50.900 I'll drag in the number of catches. 00:29:50.900 --> 00:29:53.030 And I'll say that for five seconds. 00:29:53.030 --> 00:29:55.790 So when the game is over, when I receive that message, 00:29:55.790 --> 00:29:59.420 the cat is going to say your score is this for five seconds 00:29:59.420 --> 00:30:01.933 and then the game will be over. 00:30:01.933 --> 00:30:02.600 So let's try it. 00:30:02.600 --> 00:30:03.308 I start the game. 00:30:03.308 --> 00:30:06.920 Catches and misses go back to 0, I get some instructions from the cat 00:30:06.920 --> 00:30:09.290 and I can start catching. 00:30:09.290 --> 00:30:10.830 I'll catch one. 00:30:10.830 --> 00:30:12.680 I'll catch a second one. 00:30:12.680 --> 00:30:14.180 My catches are now two. 00:30:14.180 --> 00:30:18.620 But now I'm going to let the crystals just keep falling. 00:30:18.620 --> 00:30:19.370 We missed one. 00:30:22.992 --> 00:30:24.450 We're going to miss the second one. 00:30:24.450 --> 00:30:25.500 And I'll miss a third one. 00:30:25.500 --> 00:30:27.375 I'll get out of the way just to test out what 00:30:27.375 --> 00:30:29.520 happens when I actually lose the game. 00:30:29.520 --> 00:30:30.690 That's my third miss. 00:30:30.690 --> 00:30:35.700 We broadcast that the game is over, and the cat reports that my score is two. 00:30:35.700 --> 00:30:38.250 So at this point, we now have a completed game that 00:30:38.250 --> 00:30:40.020 does sort of what we wanted it to do. 00:30:40.020 --> 00:30:41.400 The cat can move around. 00:30:41.400 --> 00:30:43.230 Crystals are falling from the sky. 00:30:43.230 --> 00:30:46.680 The cat's able to try and catch as many of those crystals as we can. 00:30:46.680 --> 00:30:49.345 And you could now play this game, share it with others. 00:30:49.345 --> 00:30:51.720 And the nice thing is that you can always add to the game 00:30:51.720 --> 00:30:54.660 if you think of new things you'd like to try inside of the game 00:30:54.660 --> 00:30:56.040 just to experiment with it. 00:30:56.040 --> 00:31:00.190 Maybe, for example, right now I think the game is maybe a little too easy. 00:31:00.190 --> 00:31:02.670 There's always just one crystal falling from the sky 00:31:02.670 --> 00:31:04.570 and I know how to move around to catch it. 00:31:04.570 --> 00:31:05.920 So let's try something. 00:31:05.920 --> 00:31:10.420 Let's make the game a little bit more challenging. 00:31:10.420 --> 00:31:13.060 Where am I creating crystals in the game? 00:31:13.060 --> 00:31:15.400 Well, I'm creating crystals here. 00:31:15.400 --> 00:31:18.430 When I receive begin, we're creating a clone of the crystal 00:31:18.430 --> 00:31:21.010 to create a brand new crystal. 00:31:21.010 --> 00:31:24.160 But let's make that a little more exciting. 00:31:24.160 --> 00:31:27.670 I'm going to put this in a forever loop, meaning we're always 00:31:27.670 --> 00:31:29.260 going to be creating crystals. 00:31:29.260 --> 00:31:33.340 Now, if I just did that to create lots and lots of crystals, what you'll see 00:31:33.340 --> 00:31:37.600 is something like this where suddenly hundreds of crystals 00:31:37.600 --> 00:31:40.220 are falling from the sky all at the same time. 00:31:40.220 --> 00:31:43.180 That's maybe a little bit too challenging. 00:31:43.180 --> 00:31:47.080 But let's add a wait here and say create a crystal 00:31:47.080 --> 00:31:49.900 and then wait 15 seconds or so. 00:31:49.900 --> 00:31:52.450 We're going to wait 15 seconds and then create 00:31:52.450 --> 00:31:56.110 a new crystal so that a new crystal appears every 15 seconds. 00:31:56.110 --> 00:31:58.917 Every 15 seconds, the game gets a little bit harder. 00:31:58.917 --> 00:32:00.250 And so now I could try it again. 00:32:00.250 --> 00:32:02.667 And you could play with that number to see what it's like. 00:32:02.667 --> 00:32:04.960 But let's try playing this game. 00:32:04.960 --> 00:32:10.020 I'm going to catch a crystal and keep doing this a few times. 00:32:10.020 --> 00:32:14.020 And after 15 seconds or so, which should be in just a couple of seconds now, 00:32:14.020 --> 00:32:17.890 we'll see what happens, it should create a second clone. 00:32:17.890 --> 00:32:20.890 And now you'll notice there are two crystals that have to try and catch. 00:32:20.890 --> 00:32:21.515 I'll catch one. 00:32:21.515 --> 00:32:22.740 Can I get the other one? 00:32:22.740 --> 00:32:25.400 All right, I caught the other one. 00:32:25.400 --> 00:32:29.110 And in another 15 seconds, we're going to see the game get even harder. 00:32:32.470 --> 00:32:34.540 Now if you notice, there are three crystals that 00:32:34.540 --> 00:32:36.667 are all out there at the same time. 00:32:36.667 --> 00:32:38.750 And maybe I'm going to start to miss some of them. 00:32:38.750 --> 00:32:42.130 I missed one already, and I'm probably going to miss a couple more now. 00:32:42.130 --> 00:32:48.190 And now I missed three, and it's telling me that my score is 14. 00:32:48.190 --> 00:32:50.390 And the crystals are still falling. 00:32:50.390 --> 00:32:53.560 And so what could I do to stop everything after the game is over? 00:32:53.560 --> 00:32:56.770 Well, after the game is over, after I say your score is something, 00:32:56.770 --> 00:33:01.300 I can go onto this block, stop all, and that's just going to stop everything. 00:33:01.300 --> 00:33:03.550 Every sprite is just going to stop operating 00:33:03.550 --> 00:33:07.630 after I say stop all so that the sprites don't continue to try to behave. 00:33:07.630 --> 00:33:09.850 Since I have multiple clones of the crystals, 00:33:09.850 --> 00:33:13.400 stop all will just now stop all of them. 00:33:13.400 --> 00:33:15.852 So hopefully you can start to see now that by combining 00:33:15.852 --> 00:33:18.310 these various different pieces, these different components, 00:33:18.310 --> 00:33:21.430 these different tools and programming from different parts of Scratch, 00:33:21.430 --> 00:33:25.910 we can start to create some creative and exciting projects as well. 00:33:25.910 --> 00:33:27.760 So now as we wrap up this course, you now 00:33:27.760 --> 00:33:30.280 have the tools you need to build projects of your own 00:33:30.280 --> 00:33:33.820 that are interesting to you by taking advantage of functions and loops 00:33:33.820 --> 00:33:36.490 and conditions and values and variables and events 00:33:36.490 --> 00:33:39.848 and more to create interesting and exciting programs of your own. 00:33:39.848 --> 00:33:41.140 And I'd encourage you to do so. 00:33:41.140 --> 00:33:43.120 Play around with this Scratch interface. 00:33:43.120 --> 00:33:47.095 Try and create a story or an animation or a game that's exciting to you. 00:33:47.095 --> 00:33:48.220 Share it with your friends. 00:33:48.220 --> 00:33:49.303 Share it with your family. 00:33:49.303 --> 00:33:51.100 And we look forward to what you create. 00:33:51.100 --> 00:33:52.580 Thank you so much for joining us. 00:33:52.580 --> 00:33:56.310 This was an introduction to Programming with Scratch.