1 00:00:00,506 --> 00:00:13,416 [ Silence ] 2 00:00:13,916 --> 00:00:14,376 >> All right. 3 00:00:14,376 --> 00:00:15,176 Hello everybody. 4 00:00:15,176 --> 00:00:18,026 Welcome to the first CS50 walkthrough. 5 00:00:18,176 --> 00:00:19,356 So these will happen every week. 6 00:00:19,356 --> 00:00:22,216 We're going to come here and discuss the problem set, 7 00:00:22,486 --> 00:00:24,496 how things need to do, how to get everything done. 8 00:00:24,496 --> 00:00:27,036 And so these will happen every week and they'll be videotaped. 9 00:00:27,036 --> 00:00:29,696 The video will be posted as soon as possible, so probably tonight 10 00:00:30,006 --> 00:00:32,666 or tomorrow morning, so you can have a nice resource 11 00:00:32,736 --> 00:00:35,556 to refer back to as you're working on the problem set. 12 00:00:35,706 --> 00:00:39,036 So my name is Tommy and I'll be leading these all year. 13 00:00:39,606 --> 00:00:41,806 First, today's music, the White Panda, 14 00:00:41,806 --> 00:00:42,926 one of my favorite mash ups. 15 00:00:43,376 --> 00:00:46,786 So today we're going to be discussing scratch, 16 00:00:47,386 --> 00:00:50,256 which is not this, but this is courtesy 17 00:00:50,256 --> 00:00:52,356 of David's Facebook wall, but this. 18 00:00:52,826 --> 00:00:56,176 So it's a program written by some folks at MIT that allows 19 00:00:56,176 --> 00:00:57,626 for some drag and drop programming. 20 00:00:57,626 --> 00:00:59,856 So we're not going to get into actual text editing and all 21 00:00:59,856 --> 00:01:01,576 that fancy machine code stuff quote yet, 22 00:01:01,986 --> 00:01:04,206 but rather we can drag and drop puzzle pieces 23 00:01:04,206 --> 00:01:06,926 to create some demos like you saw in the lecture. 24 00:01:07,876 --> 00:01:11,776 So fundamentally scratch is always going to be operating 25 00:01:11,776 --> 00:01:13,096 on what are called sprites. 26 00:01:13,166 --> 00:01:15,376 And each sprite is just an object. 27 00:01:15,576 --> 00:01:17,536 So like the cat we saw in lecture that was pet, 28 00:01:17,806 --> 00:01:19,356 that was what's called a sprite. 29 00:01:20,276 --> 00:01:23,046 So if you want to have two cats you can't just have one sprite, 30 00:01:23,046 --> 00:01:26,396 but you'd have two sprites. 31 00:01:26,396 --> 00:01:29,826 So each sprite has associated with it a set of scripts. 32 00:01:30,246 --> 00:01:32,236 And so this is what defines their behavior. 33 00:01:32,236 --> 00:01:34,236 So if you want to make the cat meow or move, 34 00:01:34,446 --> 00:01:36,386 you can do that with this scripts tab, 35 00:01:36,606 --> 00:01:37,726 which we'll see in a moment. 36 00:01:38,156 --> 00:01:40,016 And they also have costumes. 37 00:01:40,106 --> 00:01:42,316 So a sprite isn't just a single image. 38 00:01:42,316 --> 00:01:44,336 But if you want to change what the sprite looks like 39 00:01:44,336 --> 00:01:46,126 or the image that represents the sprite, 40 00:01:46,396 --> 00:01:48,786 you can do so by just adding different costumes, 41 00:01:48,866 --> 00:01:49,896 a different costume. 42 00:01:49,896 --> 00:01:52,856 So there are a couple of ways to create sprites. 43 00:01:52,856 --> 00:01:54,916 You can use an existing image on your computer 44 00:01:55,186 --> 00:01:57,096 by clicking the little folder button 45 00:01:57,656 --> 00:01:58,936 or you can draw your own sprite, 46 00:01:58,936 --> 00:02:00,486 which of course is highly encouraged 47 00:02:00,996 --> 00:02:02,356 by clicking the little paint brush. 48 00:02:02,596 --> 00:02:05,746 Or if you're feeling lucky you can just click a random sprite, 49 00:02:05,836 --> 00:02:09,336 which might not be too useful, but it exists. 50 00:02:09,406 --> 00:02:12,336 So sprites and scratch live on what's called the stage. 51 00:02:12,666 --> 00:02:15,326 And so this is the little white square that you'll see 52 00:02:15,326 --> 00:02:16,486 in the sprite environment, 53 00:02:16,586 --> 00:02:18,486 the scratch environment at the top right. 54 00:02:18,856 --> 00:02:20,846 So this is where all the sprites will move around 55 00:02:20,846 --> 00:02:22,636 and your program will actually live. 56 00:02:23,276 --> 00:02:25,086 So just like sprites have these scripts 57 00:02:25,086 --> 00:02:29,016 which define what they do, stages also can have a script, 58 00:02:29,016 --> 00:02:31,906 which kind of can do things like set defining variables 59 00:02:31,906 --> 00:02:34,786 or do things that doesn't really fit in a single sprite. 60 00:02:34,786 --> 00:02:36,896 And so we'll take a look at that. 61 00:02:36,896 --> 00:02:38,636 And stage can also have a background. 62 00:02:39,006 --> 00:02:40,846 So if you don't want to have that white thing 63 00:02:40,846 --> 00:02:42,506 in the back you can have your own image. 64 00:02:42,726 --> 00:02:44,936 And just like you can change the costume of a sprite, 65 00:02:45,176 --> 00:02:47,296 you can change the background of the stage. 66 00:02:47,706 --> 00:02:51,446 So as we saw in the lecture, all of our scripts, 67 00:02:51,726 --> 00:02:52,996 or not all of them but most of them are going 68 00:02:52,996 --> 00:02:54,446 to start with this green flag. 69 00:02:55,116 --> 00:02:57,976 And so if you just put a puzzle piece onto a sprite 70 00:02:57,976 --> 00:03:00,476 and then click the green flag, nothing's going to happen 71 00:03:00,476 --> 00:03:02,696 because that puzzle piece isn't connected to anything. 72 00:03:03,286 --> 00:03:05,616 So what a lot of puzzle pieces are going to connect to is this 73 00:03:05,686 --> 00:03:08,106 when green flag clicked, so notice the top 74 00:03:08,106 --> 00:03:09,776 of it isn't really puzzle piecey, 75 00:03:09,776 --> 00:03:11,596 you can't really connect anything to it. 76 00:03:11,596 --> 00:03:14,036 And that's just so you remember that this is kind 77 00:03:14,116 --> 00:03:16,416 of the starting point for your script and the starting point 78 00:03:16,496 --> 00:03:18,366 for our sequence of connected puzzle pieces, 79 00:03:18,646 --> 00:03:20,916 and so this is something, in scratch, called an event. 80 00:03:21,436 --> 00:03:23,546 So an event is just something that happens. 81 00:03:23,826 --> 00:03:27,136 So an event could also be like a key press. 82 00:03:27,896 --> 00:03:31,376 So just like we have the green flag clicked little swirly thing 83 00:03:31,376 --> 00:03:33,696 at the top here, we also have one for other events, 84 00:03:33,756 --> 00:03:35,516 like of ran up arrow or a space bar pressed. 85 00:03:36,116 --> 00:03:39,916 We can use these events in the same way, when a puzzle piece 86 00:03:39,916 --> 00:03:41,806 that are connected to something that starts 87 00:03:42,076 --> 00:03:44,666 with this wavy thing will be executed whenever the user 88 00:03:44,666 --> 00:03:45,656 performs that action. 89 00:03:46,466 --> 00:03:48,806 So it starts off with just when space pressed. 90 00:03:48,806 --> 00:03:49,516 But if you want to change 91 00:03:49,516 --> 00:03:51,766 that you can just click the little black arrow to the right 92 00:03:51,766 --> 00:03:52,726 of it and you'll get a drop 93 00:03:53,246 --> 00:03:56,996 down with every letter and the arrow keys. 94 00:03:56,996 --> 00:04:00,516 So we also want to take a look at conditionals. 95 00:04:00,516 --> 00:04:03,356 And this is how we're going to branch off our code. 96 00:04:03,486 --> 00:04:05,366 So we obviously don't want our sprites 97 00:04:05,366 --> 00:04:06,736 to only do one thing, right? 98 00:04:06,736 --> 00:04:08,916 We don't want it to do the same thing pressing the left arrow 99 00:04:08,916 --> 00:04:11,696 and the right arrow, we want to somehow be able to respond 100 00:04:11,986 --> 00:04:14,106 to something like the user's score going up 101 00:04:14,106 --> 00:04:16,806 or the timer running out, so we're going to do this 102 00:04:16,806 --> 00:04:18,266 with what's called a conditional. 103 00:04:18,736 --> 00:04:21,596 So it's going to create kind of fork in the road, 104 00:04:21,746 --> 00:04:24,746 each fork being those two little inset slots for puzzle pieces, 105 00:04:25,026 --> 00:04:27,716 so one is going to happen if something is true 106 00:04:27,716 --> 00:04:32,316 and the other thing is going to happen if it's not true. 107 00:04:32,536 --> 00:04:35,386 And so how do we define what is actually true? 108 00:04:35,386 --> 00:04:37,006 We're going to use these green blocks, 109 00:04:37,006 --> 00:04:39,456 which you'll notice are the little shapes that are going 110 00:04:39,456 --> 00:04:42,186 to fit into right next to where it says if. 111 00:04:42,986 --> 00:04:45,456 So we can do things like check if values are equal, 112 00:04:45,456 --> 00:04:47,156 if one value is greater than another 113 00:04:48,006 --> 00:04:49,596 or we can combine these things. 114 00:04:50,166 --> 00:04:52,616 So we can say if the timer hasn't run out yet 115 00:04:52,616 --> 00:04:54,436 and the score is at least 100, 116 00:04:54,646 --> 00:04:56,266 then we can play music, or something. 117 00:04:57,086 --> 00:04:59,996 So we can do, if two things, if both things are true, 118 00:04:59,996 --> 00:05:03,116 if one of two things are true, or if something is not true. 119 00:05:03,186 --> 00:05:06,266 And so there are puzzle pieces for those three things as well. 120 00:05:07,586 --> 00:05:10,426 So [inaudible] is also really helpful for doing things 121 00:05:10,596 --> 00:05:13,186 like collision detecting or like where your mouse is, 122 00:05:13,316 --> 00:05:16,706 so there's puzzle pieces for like where is my mouse right now 123 00:05:16,706 --> 00:05:18,336 or are these two objects touching? 124 00:05:18,636 --> 00:05:21,416 And so you'll notice that the shape of these can also fit 125 00:05:21,416 --> 00:05:22,756 into our condition block. 126 00:05:23,106 --> 00:05:26,016 So we can say if you know the score is less than 100 127 00:05:26,016 --> 00:05:29,416 and the distance to this sprite is less 128 00:05:29,486 --> 00:05:31,066 than 500 then do something. 129 00:05:31,776 --> 00:05:34,976 So in scratch we have those 8 tabs to the left 130 00:05:35,526 --> 00:05:38,016 and so the blue is going to contain everything sense things, 131 00:05:38,016 --> 00:05:40,516 like what the user is doing, what sprite's doing and kind 132 00:05:40,516 --> 00:05:43,516 of how to detect how things are interacting with each other. 133 00:05:44,006 --> 00:05:48,066 So finally we have something called variables. 134 00:05:48,176 --> 00:05:50,486 And so these you'll see a lot as you progress further 135 00:05:50,616 --> 00:05:53,216 in the class, but basically a variable is going 136 00:05:53,216 --> 00:05:55,306 to be a container for some value. 137 00:05:55,496 --> 00:05:59,236 And so that value can be a word, a letter or a number. 138 00:05:59,566 --> 00:06:00,686 But the most important thing 139 00:06:00,686 --> 00:06:02,866 about these variables is that they can change. 140 00:06:03,396 --> 00:06:06,556 So going back to our conditionals we can do things 141 00:06:06,556 --> 00:06:08,576 like compare a variable to a value 142 00:06:08,576 --> 00:06:10,876 or we can compare a variable to another variable. 143 00:06:10,876 --> 00:06:13,016 And that's when we're going to be able to start 144 00:06:13,016 --> 00:06:15,776 to do some dynamic things with our scratch program. 145 00:06:17,176 --> 00:06:19,316 So we also have loops. 146 00:06:19,616 --> 00:06:22,636 So a loop is very similar to a condition 147 00:06:23,096 --> 00:06:27,106 because we have this little if block so you can see forever if 148 00:06:27,106 --> 00:06:30,076 or repeat until, so very similar what's going to go inside 149 00:06:30,076 --> 00:06:31,466 of there is a condition. 150 00:06:31,836 --> 00:06:35,136 So if the timer has not run out yet then we can do something 151 00:06:35,136 --> 00:06:40,006 and it's going to repeat until that block is not true. 152 00:06:40,636 --> 00:06:44,186 So if we said repeat until there's nothing left, 153 00:06:44,436 --> 00:06:46,846 that's going to go until some variable reaches a point 154 00:06:47,136 --> 00:06:48,766 or we can say forever if, which is kind 155 00:06:48,766 --> 00:06:50,126 of the opposite of until. 156 00:06:50,126 --> 00:06:51,636 So there's similar things there. 157 00:06:51,876 --> 00:06:54,476 Or if we just want to have what's called an infinite loop 158 00:06:54,666 --> 00:06:56,976 or a loop that will never stop, we can just say forever. 159 00:06:57,296 --> 00:06:59,696 So we don't even have to bother specifying a condition, 160 00:06:59,926 --> 00:07:01,156 we can just so go forever 161 00:07:01,156 --> 00:07:03,766 until eventually I just want the program to end. 162 00:07:04,496 --> 00:07:07,596 So here's an example of what we would want to use a loop for. 163 00:07:07,966 --> 00:07:10,216 So we could have a little scratch script that looks 164 00:07:10,216 --> 00:07:12,696 like this, when green flag clicked we want 165 00:07:12,696 --> 00:07:13,956 to say hello three times. 166 00:07:14,506 --> 00:07:17,786 So does anyone see a little problem with this 167 00:07:17,786 --> 00:07:19,096 or how we can improve on this? 168 00:07:19,096 --> 00:07:19,616 >> [Inaudible] 169 00:07:19,616 --> 00:07:23,716 >> Yes, we can use a loop. 170 00:07:23,826 --> 00:07:26,826 So excellent. 171 00:07:26,876 --> 00:07:29,296 So which of these loops do we want to use, maybe? 172 00:07:30,036 --> 00:07:34,366 So how can we maybe spell this out? 173 00:07:34,366 --> 00:07:34,676 >> [Inaudible] 174 00:07:34,676 --> 00:07:35,896 >> Repeat until what? 175 00:07:35,896 --> 00:07:36,416 >> [Inaudible] 176 00:07:36,416 --> 00:07:41,046 >> Yes. So there's a bunch 177 00:07:41,276 --> 00:07:43,496 of different ways that we can do this. 178 00:07:43,496 --> 00:07:46,876 So we can just say, one we can just say repeat three times 179 00:07:47,576 --> 00:07:50,596 like this, but what this is essentially shorthand 180 00:07:50,596 --> 00:07:53,926 for is creating a variable that starts off at zero 181 00:07:54,186 --> 00:07:55,796 and then every time the loops goes 182 00:07:55,856 --> 00:07:58,016 through one what's called an iteration so once we get 183 00:07:58,016 --> 00:07:59,876 to that arrow there that's pointing back 184 00:07:59,876 --> 00:08:02,446 up we can say okay, let's add one to that variable 185 00:08:02,656 --> 00:08:04,986 and then the if condition we could say if we're still less 186 00:08:05,046 --> 00:08:09,476 than some value like three then we'll do it again. 187 00:08:09,476 --> 00:08:11,206 So any questions on how that works? 188 00:08:11,426 --> 00:08:13,486 So if you want to do something a fixed number 189 00:08:13,486 --> 00:08:16,236 of times you can just use this repeat 190 00:08:16,236 --> 00:08:18,176 and just specify a number. 191 00:08:18,416 --> 00:08:20,146 But if you want to do something more complicated 192 00:08:20,146 --> 00:08:21,586 than just three times in a row, 193 00:08:21,816 --> 00:08:23,666 we can use that variable approach. 194 00:08:23,666 --> 00:08:26,056 So just changing the value of a variable, making it go up, 195 00:08:26,056 --> 00:08:28,196 making it go down, and then check to see if it's 196 00:08:28,196 --> 00:08:31,736 above some value yet, and that way you can execute a loop a 197 00:08:31,736 --> 00:08:33,086 different number of times depending 198 00:08:33,086 --> 00:08:34,506 on what's going on in your program. 199 00:08:35,246 --> 00:08:36,506 So any questions so far? 200 00:08:37,136 --> 00:08:39,826 By the way, feel free to raise your hand and interrupt me. 201 00:08:39,826 --> 00:08:42,096 You don't have to wait until afterwards to ask me a question, 202 00:08:42,096 --> 00:08:43,396 just raise your hand whenever you have one. 203 00:08:43,596 --> 00:08:43,716 Yes? 204 00:08:44,516 --> 00:08:48,596 [ Inaudible ] 205 00:08:49,096 --> 00:08:51,796 >> So a few slides back we have mouse X and mouse Y, 206 00:08:52,156 --> 00:08:55,016 and so the scratch stage is basically a grid 207 00:08:55,476 --> 00:08:58,146 and so the grid has X coordinates, horizontal, 208 00:08:58,146 --> 00:08:59,866 and Y coordinates, which are vertical. 209 00:09:00,336 --> 00:09:02,056 And so as the user is interacting 210 00:09:02,056 --> 00:09:03,646 with your program you can actually get 211 00:09:04,106 --> 00:09:06,546 where their mouse pointer is on the stage. 212 00:09:06,636 --> 00:09:08,906 So if you wanted to do something like follow the mouse 213 00:09:08,906 --> 00:09:11,166 or aim a gun wherever the mouse is pointing, 214 00:09:11,406 --> 00:09:14,246 you'd want to use the mouse X and the mouse Y values. 215 00:09:14,716 --> 00:09:17,866 Other questions so far? 216 00:09:18,296 --> 00:09:27,266 Alrighty. So scratch also has a concept called messages. 217 00:09:27,566 --> 00:09:29,356 So right now if I have sprite A 218 00:09:29,356 --> 00:09:31,786 and sprite B there's really no way for those two 219 00:09:31,786 --> 00:09:32,806 to communicate, right? 220 00:09:32,986 --> 00:09:34,716 One sprite has it's own set of scripts 221 00:09:34,906 --> 00:09:37,176 and another sprite has another set of scripts. 222 00:09:37,176 --> 00:09:39,416 And there's no way for sprite A to say okay, 223 00:09:39,646 --> 00:09:42,726 I want to use something sprite B is doing. 224 00:09:42,726 --> 00:09:45,506 So the way to accomplish that is with using messages. 225 00:09:45,866 --> 00:09:49,766 So sprite A, let's say a cat, can broadcast a message. 226 00:09:49,766 --> 00:09:52,046 It's going to say okay, every sprite in the program, 227 00:09:52,206 --> 00:09:53,296 I'm going to tell you something. 228 00:09:54,076 --> 00:09:56,986 And other sprites can respond to that message. 229 00:09:58,036 --> 00:10:00,436 So as you can see with the swirly top here, 230 00:10:00,436 --> 00:10:03,236 it's another start of the sequence of puzzle pieces. 231 00:10:03,536 --> 00:10:05,526 So we can say when sprite A 232 00:10:05,526 --> 00:10:09,826 or any sprite sends this message I want to respond. 233 00:10:11,536 --> 00:10:15,576 So any questions on kind of that quick overview of scratch? 234 00:10:16,086 --> 00:10:16,206 Yes? 235 00:10:16,206 --> 00:10:17,636 >> [Inaudible] 236 00:10:17,636 --> 00:10:23,436 >> So is there a way to limit 237 00:10:23,436 --> 00:10:25,826 which sprites it broadcasts the message to? 238 00:10:25,826 --> 00:10:27,176 Unfortunately no. 239 00:10:27,176 --> 00:10:30,326 You might find yourself like oh, there should be a way to do this 240 00:10:30,326 --> 00:10:33,626 in scratch, but there isn't a lot of the time. 241 00:10:33,626 --> 00:10:36,136 And so you just kind of have to, you can prefix it with something 242 00:10:36,136 --> 00:10:40,366 like cat roar and just make sure other sprites don't respond 243 00:10:40,366 --> 00:10:41,256 to something starting with cat 244 00:10:41,796 --> 00:10:43,906 or some other conventions like that. 245 00:10:44,546 --> 00:10:47,706 Other questions? 246 00:10:47,706 --> 00:10:48,036 Yes? 247 00:10:48,036 --> 00:10:48,103 >> [Inaudible] 248 00:10:48,103 --> 00:10:52,276 >> Okay. So that's a good question. 249 00:10:52,276 --> 00:10:55,746 When is it appropriate to use variables for the sprite 250 00:10:55,956 --> 00:10:58,136 and when it is appropriate to use variables for the stage? 251 00:10:58,636 --> 00:11:01,346 So in scratch variables have something called scope. 252 00:11:01,666 --> 00:11:03,466 So there are two types of variables and we're going 253 00:11:03,466 --> 00:11:05,376 to discuss variable scope much later in the course. 254 00:11:05,376 --> 00:11:07,636 But there are two types of variables. 255 00:11:07,836 --> 00:11:10,106 One type of variable, everybody can see. 256 00:11:10,786 --> 00:11:12,836 So if set something like a timer, 257 00:11:13,016 --> 00:11:14,716 every sprite can see that timer. 258 00:11:15,346 --> 00:11:18,386 There's also something called a local variable that says if I'm 259 00:11:18,386 --> 00:11:21,436 in a sprite only this sprite can see this variable. 260 00:11:21,976 --> 00:11:25,556 So if I had a cat that has a variable called score 261 00:11:25,716 --> 00:11:29,346 and I had a bird that also has a variable also called score, 262 00:11:29,496 --> 00:11:32,036 we can do that because those two variables are separate. 263 00:11:32,946 --> 00:11:34,426 So there's two types of variable. 264 00:11:35,106 --> 00:11:38,326 So if you're doing something on the stage you probably want 265 00:11:38,326 --> 00:11:39,696 to set some type of global variable 266 00:11:39,696 --> 00:11:41,366 that all the sprites can look at. 267 00:11:41,816 --> 00:11:43,786 So I can do like in the stage I want to say okay, 268 00:11:43,786 --> 00:11:45,736 there's 100 seconds in the game I'm going to set 269 00:11:45,736 --> 00:11:47,976 that in the stage because it's not really the cat seconds, 270 00:11:47,976 --> 00:11:50,146 it's not really the bird seconds, it's for everybody, 271 00:11:50,426 --> 00:11:52,776 so that could be a global variable you could set 272 00:11:53,026 --> 00:11:53,696 in the stage. 273 00:11:54,186 --> 00:11:57,066 Other questions? 274 00:11:57,996 --> 00:11:58,366 Yes? 275 00:11:58,366 --> 00:11:58,846 >> [Inaudible] 276 00:11:58,846 --> 00:12:06,156 >> Can we define how big the space is? 277 00:12:06,156 --> 00:12:07,356 Unfortunately no. 278 00:12:07,526 --> 00:12:09,346 but there actually exists scratch mods 279 00:12:09,716 --> 00:12:11,586 if like modding scratch is your thing 280 00:12:11,766 --> 00:12:12,796 that allows you to do that. 281 00:12:13,176 --> 00:12:15,826 But unfortunately, as it stands, 282 00:12:15,826 --> 00:12:17,606 you can't change the size of the stage. 283 00:12:17,606 --> 00:12:23,306 I believe it's like 480 by 360, but that's unfortunately fixed. 284 00:12:25,116 --> 00:12:26,346 Other questions? 285 00:12:26,916 --> 00:12:31,756 Okay, so since this is a walkthrough, 286 00:12:31,946 --> 00:12:33,406 I thought it would be kind of good to walk you 287 00:12:33,456 --> 00:12:36,216 through creating a demo like we saw in lecture. 288 00:12:37,356 --> 00:12:39,976 So let's open up scratch. 289 00:12:40,486 --> 00:12:43,856 And so we're going to create a little Mario game. 290 00:12:44,296 --> 00:12:46,806 It's going to be nothing like the actual Mario but it's going 291 00:12:46,806 --> 00:12:48,546 to be using a lot of these building blocks 292 00:12:48,896 --> 00:12:49,716 that we just saw. 293 00:12:49,716 --> 00:12:51,496 So the first thing I want 294 00:12:51,496 --> 00:12:53,936 to do is set the background of my stage. 295 00:12:53,986 --> 00:12:57,116 Right now it's white and that's kind of lame, so I'm going 296 00:12:57,116 --> 00:13:02,256 to click down here on stage and you'll see now I have scripts, 297 00:13:02,476 --> 00:13:03,666 backgrounds and sounds. 298 00:13:03,856 --> 00:13:06,086 So no longer does that say costumes because I'm not working 299 00:13:06,086 --> 00:13:07,676 on a sprite, but it's a background. 300 00:13:07,676 --> 00:13:10,866 So I can click this tab and I can see all 301 00:13:10,866 --> 00:13:12,206 of the different backgrounds I have. 302 00:13:12,636 --> 00:13:15,106 So we just have one default background called background one 303 00:13:15,106 --> 00:13:17,206 and it's 480 by 360. 304 00:13:17,206 --> 00:13:18,936 So now I'm just going to click import. 305 00:13:19,976 --> 00:13:22,846 And I have a [inaudible] browser and I'm going 306 00:13:22,846 --> 00:13:26,656 to go into my backgrounds. 307 00:13:27,676 --> 00:13:30,946 So all of this will be posted on the website, by the way, 308 00:13:30,946 --> 00:13:33,886 including all the images and the actual source I used. 309 00:13:34,426 --> 00:13:36,356 So let's open this background. 310 00:13:36,826 --> 00:13:38,186 So there we go. 311 00:13:38,186 --> 00:13:40,446 So there is just a little snippet 312 00:13:40,586 --> 00:13:42,556 of the first Mario World. 313 00:13:42,936 --> 00:13:43,003 >> Whoa. 314 00:13:43,003 --> 00:13:43,896 [ Laughter ] 315 00:13:43,896 --> 00:13:52,526 >> So to do that, I clicked on the stage right here, 316 00:13:53,216 --> 00:13:57,206 then I clicked on the backgrounds tab up here, 317 00:13:57,406 --> 00:14:00,426 then clicked on import, and this is going to open 318 00:14:00,426 --> 00:14:04,236 up our little file browser and I had pre created, I just Googled 319 00:14:04,236 --> 00:14:06,186 like world 1 1 1 background and cropped it. 320 00:14:06,836 --> 00:14:09,546 And so this will be available to you if you want 321 00:14:09,546 --> 00:14:10,886 to do Mario or something. 322 00:14:11,036 --> 00:14:14,396 I just clicked okay and that changed the background 323 00:14:14,496 --> 00:14:15,276 of my stage. 324 00:14:16,246 --> 00:14:16,746 Yes? 325 00:14:16,746 --> 00:14:16,856 >> [Inaudible] 326 00:14:16,856 --> 00:14:22,416 >> So does it automatically adjust the size 327 00:14:22,416 --> 00:14:23,226 of the background? 328 00:14:23,226 --> 00:14:24,086 I don't think it does. 329 00:14:24,086 --> 00:14:26,476 I think it'll actually just show you like white or try 330 00:14:26,476 --> 00:14:29,026 to show the first 360 pixels of it or something. 331 00:14:29,456 --> 00:14:31,596 But if you want to resize it in something like Paint 332 00:14:31,676 --> 00:14:35,906 or [inaudible] then that's pretty simple to do. 333 00:14:36,306 --> 00:14:36,846 Other questions? 334 00:14:36,846 --> 00:14:37,126 Yes? 335 00:14:37,126 --> 00:14:37,486 >> [Inaudible] 336 00:14:37,486 --> 00:14:38,156 >> Oh sure. 337 00:14:38,156 --> 00:14:45,546 So can you get images off the internet and put them in here? 338 00:14:45,546 --> 00:14:47,636 Yes. So if you just download the image, which would be 339 00:14:47,636 --> 00:14:50,666 like a jpeg or a png file, so it'll be saved 340 00:14:50,666 --> 00:14:51,946 in your downloads folder somewhere, 341 00:14:52,326 --> 00:14:54,626 then when you click import you just have to navigate 342 00:14:54,626 --> 00:14:56,866 to that folder and double click it and then it'll be inside 343 00:14:56,866 --> 00:14:58,166 of your scratch project. 344 00:15:00,406 --> 00:15:01,646 Other questions so far? 345 00:15:01,646 --> 00:15:02,326 All right. 346 00:15:04,096 --> 00:15:06,446 So we can get ride of this white background. 347 00:15:06,486 --> 00:15:07,736 I'm just going to click this X right here 348 00:15:07,736 --> 00:15:08,716 because I don't need it anymore 349 00:15:08,716 --> 00:15:11,716 as this is the only background that we'll be using. 350 00:15:12,316 --> 00:15:14,886 So now I also probably want to change the look of this cat. 351 00:15:15,976 --> 00:15:17,936 So I'm going to click on where it says sprite one, 352 00:15:18,636 --> 00:15:19,656 and you'll notice up here 353 00:15:19,656 --> 00:15:23,066 in the costumes tab I actually have two costumes, 354 00:15:23,066 --> 00:15:24,196 so I can just delete it. 355 00:15:24,196 --> 00:15:30,286 So again, I'm going to click import and navigate back 356 00:15:30,286 --> 00:15:31,326 to where I have everything, 357 00:15:31,546 --> 00:15:36,746 should have picked a better place, all right, 358 00:15:37,536 --> 00:15:41,736 so there is one Mario. 359 00:15:42,406 --> 00:15:45,006 So that's Mario facing right. 360 00:15:45,406 --> 00:15:48,326 But when the user moves Mario around, I probably want him 361 00:15:48,326 --> 00:15:49,766 to face the other direction. 362 00:15:50,336 --> 00:15:53,376 So I actually can import a second costume that's just Mario 363 00:15:53,376 --> 00:15:55,216 standing there facing the other direction. 364 00:15:55,506 --> 00:15:58,336 So I go back into import and then I just flip the image 365 00:15:58,426 --> 00:16:01,146 and there's Mario standing right. 366 00:16:01,796 --> 00:16:04,586 Now this sprite has two costumes. 367 00:16:05,466 --> 00:16:07,546 By default it's just going to use the one that we click on, 368 00:16:07,546 --> 00:16:10,606 so I clicked on one and you'll notice that Mario is facing 369 00:16:10,606 --> 00:16:11,636 in the other direction again. 370 00:16:12,656 --> 00:16:15,706 So questions on how I change the appearance of different sprites? 371 00:16:17,136 --> 00:16:19,906 >> Did you also download your sprites off the internet? 372 00:16:20,326 --> 00:16:22,236 >> Yes. So I unfortunately can't draw 373 00:16:22,516 --> 00:16:24,816 so I did download these sprites off the internet. 374 00:16:24,816 --> 00:16:26,666 I just Googled like Mario sprites. 375 00:16:27,626 --> 00:16:27,996 What's that? 376 00:16:27,996 --> 00:16:28,176 >> [Inaudible] 377 00:16:28,176 --> 00:16:30,776 >> Yes. So these are just images. 378 00:16:30,776 --> 00:16:33,046 I believe they're all jpegs or gifs or something like that. 379 00:16:33,276 --> 00:16:35,076 Yes, I didn't do anything fancy to these images. 380 00:16:35,076 --> 00:16:37,656 I just downloaded them, resized them a little bit 381 00:16:37,656 --> 00:16:39,016 and then imported them into scratch. 382 00:16:39,016 --> 00:16:39,083 >> [Inaudible] 383 00:16:39,083 --> 00:16:45,526 >> So do I have a specific size of the sprites? 384 00:16:45,526 --> 00:16:48,936 You can see the size in scratch, so this one happens to be 26 385 00:16:48,936 --> 00:16:52,136 by 32, but I really could have done any size that I wanted. 386 00:16:52,426 --> 00:16:57,176 So as long as it's not bigger than that 480 by 360 and it fits 387 00:16:57,796 --> 00:17:01,736 on the stage you can use that. 388 00:17:02,596 --> 00:17:02,686 Yes? 389 00:17:02,686 --> 00:17:03,996 >> [Inaudible] 390 00:17:03,996 --> 00:17:06,266 >> So if you download an image that has a white background, 391 00:17:06,266 --> 00:17:07,316 how do you get rid of it? 392 00:17:07,486 --> 00:17:11,086 So this is kind of more like an image editing PhotoShop trick. 393 00:17:11,206 --> 00:17:15,286 But a lot of image editors have something that takes some color, 394 00:17:15,286 --> 00:17:18,076 like white and can set it to transparency and then 395 00:17:18,076 --> 00:17:21,206 if you just save that as a png, portable networks graphic, 396 00:17:21,316 --> 00:17:22,986 it'll retain that transparency. 397 00:17:23,436 --> 00:17:25,446 So if you want to do something like select by color 398 00:17:25,446 --> 00:17:28,676 and then something like, along the lines of color to alpha 399 00:17:28,846 --> 00:17:31,016 or something like that it should be able to wipe out the white 400 00:17:31,016 --> 00:17:32,086 and make it transparent. 401 00:17:32,356 --> 00:17:34,386 Unfortunately more of an image editing thing 402 00:17:34,386 --> 00:17:37,186 than a scratch thing, but that's along the lines 403 00:17:37,186 --> 00:17:37,776 of how you'd do it. 404 00:17:38,716 --> 00:17:38,966 Yes? 405 00:17:39,516 --> 00:17:48,996 [ Inaudible ] 406 00:17:49,496 --> 00:17:52,456 >> Yes, so that is, yes, so that is what I did 407 00:17:52,456 --> 00:17:54,296 but you can do it in scratch, actually. 408 00:17:54,746 --> 00:17:58,856 If you go over here to, let's see, if you go over here to, 409 00:17:58,856 --> 00:18:02,966 yes, so if you go over here 410 00:18:02,966 --> 00:18:06,836 to motion you can actually do things like rotate it. 411 00:18:07,016 --> 00:18:10,196 Or if you go over here to looks you can do things 412 00:18:10,566 --> 00:18:12,026 like grow it or shrink it. 413 00:18:12,926 --> 00:18:15,736 But in this case, I did, I just literally downloaded Mario, 414 00:18:15,736 --> 00:18:18,026 opened PhotoShop, said flip vertically 415 00:18:18,256 --> 00:18:19,926 and then used the other one. 416 00:18:20,726 --> 00:18:21,106 Yes? 417 00:18:21,106 --> 00:18:22,996 >> [Inaudible] 418 00:18:22,996 --> 00:18:26,766 >> Yes. Yes so scratch also does have an image editor. 419 00:18:26,766 --> 00:18:28,236 It's a very rudimentary one. 420 00:18:28,236 --> 00:18:30,236 You'd be able to click edit and then I'd be able 421 00:18:30,236 --> 00:18:31,386 to flip it here as well. 422 00:18:31,386 --> 00:18:34,346 Not quote PhotoShop but you can do some basic things. 423 00:18:34,966 --> 00:18:41,026 Other questions on appearance of things? 424 00:18:42,266 --> 00:18:44,906 Okay. So let's make Mario move. 425 00:18:45,856 --> 00:18:49,946 So what block do I probably want to use? 426 00:18:50,416 --> 00:18:52,196 So we looked at different types of puzzle pieces. 427 00:18:52,196 --> 00:18:54,786 What's one type of puzzle piece that we saw that I might want 428 00:18:54,786 --> 00:18:57,456 to use to make Mario go right when I press the right arrow 429 00:18:57,456 --> 00:18:58,886 and left when I press the left arrow? 430 00:18:58,886 --> 00:18:58,996 >> [Inaudible] 431 00:18:58,996 --> 00:19:01,026 >> So yes, an event. 432 00:19:01,146 --> 00:19:03,466 So we're going to use motion after the event, 433 00:19:03,686 --> 00:19:04,996 but first we're going to use an event. 434 00:19:05,226 --> 00:19:08,406 And these are found in the yellow orange-ish control tab. 435 00:19:09,146 --> 00:19:11,366 So I'm going to click here and you'll see 436 00:19:11,366 --> 00:19:12,566 when space key pressed. 437 00:19:13,026 --> 00:19:15,546 Remember, we can change that with that little black arrow. 438 00:19:15,546 --> 00:19:19,416 So I'm going to drag this little guy in and so now its part 439 00:19:19,416 --> 00:19:21,946 of the Mario sprite because I have him selected. 440 00:19:22,226 --> 00:19:24,266 So before we do anything else we probably want 441 00:19:24,266 --> 00:19:26,636 to give Mario a better name than sprite one. 442 00:19:27,226 --> 00:19:30,956 So if I come up here and double click, I can type in Mario. 443 00:19:31,326 --> 00:19:33,516 And now this sprite I will be referring 444 00:19:33,516 --> 00:19:35,126 to as Mario and not sprite one. 445 00:19:35,126 --> 00:19:36,426 And this is going to be pretty helpful 446 00:19:36,426 --> 00:19:39,636 if you start using the same image for multiple sprites, 447 00:19:39,636 --> 00:19:42,226 how to tell them apart other than sprite 1 through 10. 448 00:19:43,226 --> 00:19:44,536 So we renamed him. 449 00:19:44,746 --> 00:19:45,796 We can come into this block. 450 00:19:46,476 --> 00:19:48,876 We can come down to the right arrow. 451 00:19:48,876 --> 00:19:53,716 And so now it says when the right arrow key is pressed. 452 00:19:53,716 --> 00:19:57,436 So now I want to do two things, I want to make sure 453 00:19:57,436 --> 00:19:59,936 that I have the right costume, so make sure 454 00:19:59,936 --> 00:20:01,316 that I have the Mario facing right. 455 00:20:01,846 --> 00:20:04,386 And I want to move him. 456 00:20:04,446 --> 00:20:07,466 So to change the costume we're going to go over here to looks 457 00:20:08,246 --> 00:20:09,486 and switch to costume. 458 00:20:10,706 --> 00:20:15,516 So right there, so we have Mario standing and Mario standing, 459 00:20:15,516 --> 00:20:23,526 I got cut off, so let's just say Mario right and Mario left, 460 00:20:24,476 --> 00:20:26,256 so just type in there and click enter. 461 00:20:26,576 --> 00:20:29,436 Let's go back over to scripts and we can say switch 462 00:20:29,436 --> 00:20:32,886 to costume Mario right because I pressed the right arrow key. 463 00:20:34,326 --> 00:20:36,516 So now we want to actually move Mario. 464 00:20:36,896 --> 00:20:45,146 So let's go up here to motion and let's say change X by 10. 465 00:20:45,946 --> 00:20:47,416 So we'll just keep that as the default, 466 00:20:48,076 --> 00:20:50,576 10 being the default value, we can just keep that. 467 00:20:50,996 --> 00:20:53,696 And so now when I run my script, 468 00:20:54,566 --> 00:20:57,266 if I hit right, Mario goes right. 469 00:20:57,956 --> 00:20:59,086 So that's nice. 470 00:20:59,216 --> 00:21:01,236 So we can make him go left in the same way. 471 00:21:02,246 --> 00:21:05,486 Just drag this over, when the left arrow is pressed, 472 00:21:06,926 --> 00:21:08,556 switch to the left costume. 473 00:21:09,606 --> 00:21:13,586 And now what do we want to change the X by? 474 00:21:13,586 --> 00:21:13,986 >> [Inaudible] 475 00:21:13,986 --> 00:21:17,506 >> Exactly, so we're going to change the X by negative 10. 476 00:21:18,616 --> 00:21:21,886 So we can just double click in here and type in a minus sign 477 00:21:23,186 --> 00:21:25,926 and now when I click left he's going to go left 478 00:21:26,566 --> 00:21:27,786 and right he's going to go right. 479 00:21:27,786 --> 00:21:31,646 So you might say to yourself every time you run your program 480 00:21:31,646 --> 00:21:33,996 you have to click Mario and drag it over there 481 00:21:33,996 --> 00:21:35,756 and then you're ready to go. 482 00:21:35,756 --> 00:21:38,446 So that's not really the best user experience. 483 00:21:38,576 --> 00:21:40,956 We many kind of want to click green flag and then Mario's 484 00:21:40,956 --> 00:21:42,276 at the start and he's ready to go. 485 00:21:43,076 --> 00:21:45,786 So now we're going to want to star using that green flag. 486 00:21:46,216 --> 00:21:48,286 So now as soon as the user clicks that green flag, 487 00:21:48,726 --> 00:21:50,796 we want to put Mario where he needs to be. 488 00:21:51,676 --> 00:21:53,276 So let's go over here to control, 489 00:21:53,536 --> 00:21:58,596 when the green flag is clicked, now instead of changing the X 490 00:21:58,646 --> 00:22:01,276 by a value, which says okay, Mario is at some value. 491 00:22:01,456 --> 00:22:02,486 We want to change that. 492 00:22:02,816 --> 00:22:05,776 We want to change the value so we're going to just set it 493 00:22:06,646 --> 00:22:07,686 to some coordinates 494 00:22:08,516 --> 00:22:10,356 and unfortunately the best we can do is kind 495 00:22:10,356 --> 00:22:11,876 of guess and check. 496 00:22:11,876 --> 00:22:15,056 So here I see a negative 203, a negative 119, 497 00:22:15,576 --> 00:22:21,036 so let's say negative 203, negative 119. 498 00:22:21,726 --> 00:22:24,336 So now even if somehow Mario ends up over here, 499 00:22:24,986 --> 00:22:27,746 once I press the green arrow Mario's going to jump 500 00:22:28,246 --> 00:22:29,196 to where he needs to be. 501 00:22:29,196 --> 00:22:31,696 So we probably also want to make sure he's facing right, 502 00:22:32,446 --> 00:22:38,316 so just switch the costume, Mario right. 503 00:22:38,826 --> 00:22:43,096 So now our game is all set up. 504 00:22:43,096 --> 00:22:47,136 Any questions on what we did so far? 505 00:22:47,356 --> 00:22:47,686 Yes? 506 00:22:48,516 --> 00:23:01,096 [ Inaudible ] 507 00:23:01,596 --> 00:23:03,596 >> Yes. So the question is do the order 508 00:23:03,596 --> 00:23:04,576 of these pieces matter? 509 00:23:04,976 --> 00:23:05,706 And they do. 510 00:23:06,056 --> 00:23:09,686 So whatever piece happens first, so whatever's closest 511 00:23:09,686 --> 00:23:11,196 to that top piece, so the higher 512 00:23:11,196 --> 00:23:12,936 up pieces will be executed first. 513 00:23:13,546 --> 00:23:15,286 So if these were in the other order, 514 00:23:15,286 --> 00:23:16,916 what actually would happen is he would move 515 00:23:16,916 --> 00:23:18,026 and then he would face right. 516 00:23:18,516 --> 00:23:21,036 So just kind of holding down the arrow key you really wouldn't 517 00:23:21,036 --> 00:23:23,386 notice anything, but if you just pressed it once it would look 518 00:23:23,386 --> 00:23:23,936 kind of weird. 519 00:23:24,356 --> 00:23:25,326 And so it does. 520 00:23:25,326 --> 00:23:27,506 It does matter what order the puzzle pieces go in. 521 00:23:28,226 --> 00:23:30,626 some things don't matter, like if you're setting a bunch 522 00:23:30,626 --> 00:23:32,366 of variables and it doesn't really matter what order they're 523 00:23:32,366 --> 00:23:33,546 set in it doesn't. 524 00:23:33,546 --> 00:23:36,116 but most of the time you're going to want to make sure okay, 525 00:23:36,116 --> 00:23:37,886 I'm changing the costume and then I'm moving him 526 00:23:38,096 --> 00:23:39,706 and my puzzle pieces are in the right order. 527 00:23:40,586 --> 00:23:40,836 Yes? 528 00:23:41,516 --> 00:23:47,956 [ Inaudible ] 529 00:23:48,456 --> 00:23:50,906 >> So how fast do the puzzle pieces execute? 530 00:23:51,526 --> 00:23:54,476 So basically the next puzzle piece will not execute 531 00:23:54,476 --> 00:23:56,646 until the puzzle piece above it is done. 532 00:23:57,226 --> 00:24:00,226 So if this were not change X by 10, but change X by 100, 533 00:24:00,576 --> 00:24:03,836 or we can also do, which we'll see shortly, 534 00:24:03,836 --> 00:24:06,266 we can actually tell it how long it's going to take. 535 00:24:06,936 --> 00:24:10,496 We have glide one second, so if we said like glide 5 seconds, 536 00:24:10,526 --> 00:24:12,186 and then change the costume, you would notice. 537 00:24:12,286 --> 00:24:15,326 So in this case you wouldn't really, so it really depends 538 00:24:15,326 --> 00:24:17,526 on what you're doing that's going to define 539 00:24:17,566 --> 00:24:19,726 if people will notice or if order really does matter. 540 00:24:19,986 --> 00:24:23,356 Assume most of the time that it does because it will shortly. 541 00:24:25,176 --> 00:24:26,186 Other questions so far? 542 00:24:27,226 --> 00:24:27,576 Yes? 543 00:24:28,516 --> 00:24:35,386 [ Inaudible ] 544 00:24:35,886 --> 00:24:37,826 >> So how would I set a different direction? 545 00:24:38,516 --> 00:24:44,326 [ Inaudible ] 546 00:24:44,826 --> 00:24:48,176 >> Oh, sure, so we also have this point 547 00:24:48,176 --> 00:24:49,626 in direction, this point towards. 548 00:24:50,866 --> 00:24:56,296 So we can say turn 10 degrees and wait a 10th of a second, 549 00:24:56,296 --> 00:24:58,596 turn another 10 degrees, wait a 10th of a second. 550 00:24:58,596 --> 00:25:00,716 So that's actually a good candidate for a loop, right? 551 00:25:00,716 --> 00:25:03,176 We can say I want to make 180 degree turn, 552 00:25:03,176 --> 00:25:06,896 so 18 times I want you to turn 10 degrees and wait a 10th 553 00:25:06,896 --> 00:25:08,126 of a second and then basically what 554 00:25:08,126 --> 00:25:09,126 that would do is animate it. 555 00:25:09,956 --> 00:25:11,806 So we're not doing that here, but that's sort 556 00:25:11,806 --> 00:25:14,306 of how we're going to start thinking about things. 557 00:25:14,306 --> 00:25:15,846 There's not animate button 558 00:25:15,846 --> 00:25:17,616 so how can we make our own animate button? 559 00:25:18,076 --> 00:25:20,016 And so usually it's some combination of loops 560 00:25:20,016 --> 00:25:23,076 and variables is how we're going to be able to do that. 561 00:25:23,886 --> 00:25:23,976 Yes? 562 00:25:24,516 --> 00:25:41,666 [ Inaudible ] 563 00:25:42,166 --> 00:25:44,686 >> Sure, so we'll actually see that shortly, 564 00:25:44,686 --> 00:25:46,106 how we can use ifs in variables. 565 00:25:46,106 --> 00:25:49,126 So we're just not sure quite how to react to variables just yet, 566 00:25:49,126 --> 00:25:50,576 but we'll see that very shortly. 567 00:25:50,976 --> 00:25:51,146 Yes? 568 00:25:52,516 --> 00:26:09,096 [ Inaudible ] 569 00:26:09,596 --> 00:26:13,486 >> Oh, so that just might be another scratch limitation. 570 00:26:13,946 --> 00:26:16,896 What can be helpful is duplicating. 571 00:26:17,836 --> 00:26:20,746 So if you want to have like, so how do we kind 572 00:26:21,236 --> 00:26:22,746 of make editing faster? 573 00:26:23,056 --> 00:26:25,466 Unfortunately because scratch is so simple there aren't a lot 574 00:26:25,466 --> 00:26:27,826 of cool controls like dragging things among sprites, 575 00:26:28,196 --> 00:26:31,206 but you'll find the duplicate really helpful 576 00:26:31,346 --> 00:26:32,756 if you're creating a lot of similar sprites. 577 00:26:33,186 --> 00:26:35,186 But again, it's just one of those scratch is trying 578 00:26:35,186 --> 00:26:36,246 to be simple and so there aren't 579 00:26:36,246 --> 00:26:38,616 like those super fancy editing things quite yet. 580 00:26:39,516 --> 00:26:43,586 [ Inaudible ] 581 00:26:44,086 --> 00:26:45,926 >> Okay. So if you wanted to do that we could just duplicate 582 00:26:45,926 --> 00:26:47,966 and then you could actually just drag it, oh, yes you can, 583 00:26:47,966 --> 00:26:48,826 so you can just drag it there. 584 00:26:48,826 --> 00:26:50,856 And that's how to move from a sprite to another sprite 585 00:26:50,856 --> 00:26:51,986 or a sprite to a stage. 586 00:26:52,076 --> 00:26:52,586 All right. 587 00:26:53,216 --> 00:26:56,076 So now that Mario can move left and right, 588 00:26:56,676 --> 00:26:58,166 let's make Mario jump. 589 00:26:58,926 --> 00:27:02,096 And so this is going to be a little bit more complicated, 590 00:27:02,396 --> 00:27:04,616 but we're going to start looking 591 00:27:04,616 --> 00:27:06,746 at that glide instead of the change. 592 00:27:07,486 --> 00:27:11,356 So we're going to start off with the same thing we used before, 593 00:27:11,496 --> 00:27:14,886 this something key pressed, and we're going to use the up arrow. 594 00:27:15,596 --> 00:27:20,736 And so now if we go over here to glide, you'll notice 595 00:27:20,736 --> 00:27:25,256 that we have glide to a specific X and Y coordinate. 596 00:27:25,876 --> 00:27:30,076 So we can't just glide and say change it by negative 10 597 00:27:30,076 --> 00:27:31,516 and then it'll basically animate for you. 598 00:27:31,606 --> 00:27:34,396 Instead, we can only say go to a certain position. 599 00:27:35,046 --> 00:27:37,586 But when we jump, we don't want to be jumping always 600 00:27:37,586 --> 00:27:39,026 at some fixed X value. 601 00:27:39,026 --> 00:27:41,756 We want to jump starting from where Mario actually is, right? 602 00:27:42,806 --> 00:27:46,606 So we need to start using that sensing tab. 603 00:27:46,606 --> 00:27:48,646 And we do want to use this glide block, 604 00:27:48,686 --> 00:27:50,246 so let's put this glide block here. 605 00:27:51,506 --> 00:27:54,056 And now let's go to sensing. 606 00:27:54,526 --> 00:27:59,676 So now can anyone here see any blocks that we might want to use 607 00:28:00,346 --> 00:28:03,716 to kind of increment or decrement how high he is, 608 00:28:03,716 --> 00:28:05,616 so changing it rather than just setting it? 609 00:28:06,476 --> 00:28:07,576 So make it, change it 610 00:28:07,576 --> 00:28:10,056 to something that's relative to where Mario is. 611 00:28:10,056 --> 00:28:10,566 >> [Inaudible] 612 00:28:10,566 --> 00:28:15,306 >> Yes. So we have this X position of Mario. 613 00:28:16,126 --> 00:28:18,756 And so what I thought wasn't immediately obvious is 614 00:28:18,756 --> 00:28:22,266 that we can actually take this and drag it in here. 615 00:28:23,356 --> 00:28:26,676 So now we want to glide to the X position of Mario. 616 00:28:26,966 --> 00:28:28,456 Now do we just want to keep that there? 617 00:28:28,456 --> 00:28:32,166 Is there anything else we need to do to that? 618 00:28:33,476 --> 00:28:34,526 No. we don't need to change it. 619 00:28:34,526 --> 00:28:35,336 It makes sense. 620 00:28:35,336 --> 00:28:36,866 If we jump upward then he's not moving 621 00:28:36,866 --> 00:28:37,676 to the left or to the right. 622 00:28:38,036 --> 00:28:38,886 So that makes sense. 623 00:28:39,706 --> 00:28:43,486 But now we want him to jump up some fixed height. 624 00:28:44,216 --> 00:28:47,196 So we can't just say drag the Y position of Mario 625 00:28:47,196 --> 00:28:48,856 into Y we need to do something. 626 00:28:49,236 --> 00:28:53,506 Question before we do that? 627 00:28:53,506 --> 00:28:54,146 >> [Inaudible] 628 00:28:54,146 --> 00:28:55,826 >> So will this halt any forward progress 629 00:28:55,826 --> 00:28:56,996 that he's making when he jumps? 630 00:28:57,106 --> 00:29:00,626 Yes. Because we're saying jump to exactly where you are, 631 00:29:00,916 --> 00:29:01,856 but move the Y upwards. 632 00:29:01,856 --> 00:29:04,386 So you could so some fancy like arc thing with sine's 633 00:29:04,386 --> 00:29:05,906 and cosines or something, 634 00:29:05,906 --> 00:29:08,106 I don't know, I'm not good at math. 635 00:29:08,306 --> 00:29:10,526 But since this is just P-set zero we're just going 636 00:29:10,526 --> 00:29:11,566 to halt this forward progress. 637 00:29:11,566 --> 00:29:16,616 So not particularly helpful for an actual Mario game. 638 00:29:16,756 --> 00:29:20,716 Okay, so we want to modify this Y value, 639 00:29:20,716 --> 00:29:23,736 so we can just say glide to the X position and Y position 640 00:29:23,736 --> 00:29:25,376 or he's just going to sit there. 641 00:29:25,376 --> 00:29:28,456 So now we need to go over to this green operator's tab. 642 00:29:29,326 --> 00:29:33,366 And what we're going to say is we need to actually click it, 643 00:29:33,626 --> 00:29:38,026 jump to some value plus some other value. 644 00:29:39,386 --> 00:29:43,656 So in this case we want to do, what's on the left here? 645 00:29:43,656 --> 00:29:44,356 >> [Inaudible] 646 00:29:44,356 --> 00:29:45,956 >> Yes. Y position of Mario. 647 00:29:46,296 --> 00:29:48,576 So this drags in there and we have puzzle pieces 648 00:29:48,576 --> 00:29:50,316 in puzzle pieces in puzzle pieces 649 00:29:50,316 --> 00:29:56,756 and we can say the Y position and then plus, I don't know, 50. 650 00:29:57,576 --> 00:29:59,566 Hopefully that's not too high. 651 00:29:59,906 --> 00:30:06,526 So let's pick a value like .12, totally not predetermined. 652 00:30:06,966 --> 00:30:10,846 And so after he glides up there we want him to glide back 653 00:30:10,846 --> 00:30:14,126 down to complete the jump or go back to where he was before. 654 00:30:14,626 --> 00:30:16,646 So we'll just do the same thing. 655 00:30:17,656 --> 00:30:26,316 So we'll glide 0.12 to the X position of Mario 656 00:30:26,776 --> 00:30:29,316 and now what do we want to have on this right side? 657 00:30:29,316 --> 00:30:35,466 Which of these green blocks do we want to use? 658 00:30:35,606 --> 00:30:36,936 So we just added 50. 659 00:30:37,136 --> 00:30:40,876 What do we need to do for him to fall back down? 660 00:30:40,876 --> 00:30:41,136 >> [Inaudible] 661 00:30:41,136 --> 00:30:42,946 >> Right. Exactly. 662 00:30:42,946 --> 00:30:45,556 So we're going to drag the minus guy 663 00:30:46,236 --> 00:31:00,116 and we can say the Y position of Mario minus, okay, minus 50. 664 00:31:00,476 --> 00:31:01,756 All right. 665 00:31:01,846 --> 00:31:03,046 So let's run our script. 666 00:31:03,586 --> 00:31:07,716 Now we click up, he's going to jump. 667 00:31:08,026 --> 00:31:12,256 So does anyone see a potential how we can improve this? 668 00:31:12,496 --> 00:31:14,006 It's a little design problem here. 669 00:31:14,006 --> 00:31:14,073 >> [Inaudible] 670 00:31:14,073 --> 00:31:21,376 >> Yes. So we could improve the physics of it, that's true. 671 00:31:22,396 --> 00:31:26,266 Unfortunately I'm not good at physics either. 672 00:31:26,266 --> 00:31:27,476 So what else? 673 00:31:27,476 --> 00:31:31,986 Does anyone see like a little redundancy here? 674 00:31:31,986 --> 00:31:32,616 >> [Inaudible] 675 00:31:32,616 --> 00:31:33,166 >> Exactly. 676 00:31:33,166 --> 00:31:36,286 So we can store, not the XY position, 677 00:31:36,286 --> 00:31:37,836 but how much we're jumping. 678 00:31:38,216 --> 00:31:40,596 So let's say I'm a Nintendo developer 679 00:31:40,596 --> 00:31:41,446 and I just finished this. 680 00:31:41,446 --> 00:31:42,006 It's awesome. 681 00:31:42,006 --> 00:31:42,846 We're ready to ship it. 682 00:31:43,106 --> 00:31:45,116 And someone says to me well, we'd actually like Mario 683 00:31:45,116 --> 00:31:48,176 to jump a little higher, so I actually have 684 00:31:48,176 --> 00:31:51,066 to change both of these 50s to 60s. 685 00:31:51,406 --> 00:31:52,806 Not a big deal here. 686 00:31:53,156 --> 00:31:56,656 But let's say that I had 10 million sprites and I said 50 687 00:31:56,656 --> 00:31:59,376 in all of those 10 million sprites and now my boss comes 688 00:31:59,376 --> 00:32:01,446 over to me and says no, they need to be a little bit higher. 689 00:32:01,866 --> 00:32:04,846 I'd have to go in and change each of those 10 million values, 690 00:32:05,596 --> 00:32:06,956 so that's not the best idea. 691 00:32:07,486 --> 00:32:10,416 So what we can do here is use a variable. 692 00:32:10,416 --> 00:32:14,046 So let's come over here to the variables tab. 693 00:32:14,396 --> 00:32:16,956 And you'll notice that there's nothing. 694 00:32:17,566 --> 00:32:19,396 So we can make a new variable. 695 00:32:19,966 --> 00:32:25,416 And we can call it jump height and then you'll notice here 696 00:32:25,416 --> 00:32:27,796 that I have these two options, for all sprites 697 00:32:27,856 --> 00:32:29,156 and for this sprite only. 698 00:32:29,156 --> 00:32:30,666 So this is what I was saying before. 699 00:32:30,786 --> 00:32:32,146 So if you want to create a variable 700 00:32:32,386 --> 00:32:34,596 that every sprite can see I'm going to want 701 00:32:34,596 --> 00:32:35,626 to say for all sprites. 702 00:32:36,106 --> 00:32:38,906 Or if I want to say for this sprite only I'm going 703 00:32:38,906 --> 00:32:39,596 to click this. 704 00:32:39,596 --> 00:32:41,326 In this case, Mario's going to be jump, 705 00:32:41,326 --> 00:32:42,766 only Mario will be jumping 706 00:32:42,976 --> 00:32:46,486 so only Mario can see this variable called jump height. 707 00:32:47,996 --> 00:32:50,366 So if you don't believe me, if I come over here 708 00:32:50,366 --> 00:32:52,966 and click the stage, you'll notice there are no variables 709 00:32:53,146 --> 00:32:55,106 because the stage cannot see jump height, 710 00:32:55,556 --> 00:32:58,436 only Mario can see jump height. 711 00:32:59,676 --> 00:33:02,806 So after we've created this variable. 712 00:33:03,746 --> 00:33:03,866 Yes? 713 00:33:03,866 --> 00:33:04,556 >> [Inaudible] 714 00:33:04,556 --> 00:33:07,806 >> So Mario left and Mario right are the same sprite, 715 00:33:07,916 --> 00:33:09,296 so does it affect both of them? 716 00:33:09,296 --> 00:33:11,276 It does because there's only one sprite, 717 00:33:11,986 --> 00:33:14,666 he just has two different costumes or images 718 00:33:14,856 --> 00:33:15,716 that would be displayed. 719 00:33:16,436 --> 00:33:18,546 So we're just operating on this one Mario, 720 00:33:18,826 --> 00:33:21,276 but he has two different appearances. 721 00:33:22,616 --> 00:33:30,656 So let's say that we want to set the jump height value. 722 00:33:30,996 --> 00:33:35,286 So we can say set jump height to and we use 50, 723 00:33:35,416 --> 00:33:39,216 so we can set jump height to 50. 724 00:33:39,886 --> 00:33:45,126 so now we can just drag jump height in where it says 50, 725 00:33:45,126 --> 00:33:52,056 and so now changing how high Mario jumps is just a single 726 00:33:52,056 --> 00:33:55,436 change of a value, rather than what could be 10's of millions 727 00:33:55,436 --> 00:33:56,516 of changes to a value. 728 00:33:57,626 --> 00:34:01,616 So any question on how we're using that variable there? 729 00:34:01,846 --> 00:34:02,086 Yes? 730 00:34:03,516 --> 00:34:10,056 [ Inaudible ] 731 00:34:10,556 --> 00:34:13,826 >> No, so what I clicked on was make a variable and then 732 00:34:13,826 --> 00:34:16,386 that gave me a pop up, I just said jump height 733 00:34:16,566 --> 00:34:18,556 and then it created this over here. 734 00:34:18,556 --> 00:34:18,796 >> [Inaudible] 735 00:34:18,796 --> 00:34:25,786 >> Oh, so in set jump height to, I'd have 50 here. 736 00:34:25,786 --> 00:34:28,386 And so this says whenever the program starts I want 737 00:34:28,386 --> 00:34:30,416 to make sure that jump height is at the correct value. 738 00:34:30,806 --> 00:34:33,836 So if later Mario wants to get like a super mushroom 739 00:34:33,836 --> 00:34:36,906 where he can jump higher, I can potentially change that value. 740 00:34:37,166 --> 00:34:39,336 But when the program starts we want to make sure 741 00:34:39,416 --> 00:34:45,446 that he can just jump 50. 742 00:34:45,446 --> 00:34:47,886 Okay. So now Mario can jump. 743 00:34:49,196 --> 00:34:51,836 However we probably want to make Mario do something other 744 00:34:51,836 --> 00:34:52,246 than jump. 745 00:34:53,146 --> 00:34:54,686 So let's add another sprite. 746 00:34:55,536 --> 00:34:59,266 So I'm going to click on this folder and it's going 747 00:34:59,266 --> 00:35:00,486 to open up my images again. 748 00:35:01,086 --> 00:35:05,086 And if I click on block, I click okay, you'll notice 749 00:35:05,086 --> 00:35:06,676 that I just created another sprite 750 00:35:06,676 --> 00:35:11,416 and it's costume is the image that I clicked on. 751 00:35:12,316 --> 00:35:18,776 So this is just that little coin block, yes, the coin block, 752 00:35:18,956 --> 00:35:23,056 and so what I want to do is first change the sprite one 753 00:35:23,476 --> 00:35:26,406 to say block, so that we have a better name to work with. 754 00:35:26,886 --> 00:35:29,536 Then come over here to scripts, where we're ultimately going 755 00:35:29,536 --> 00:35:31,746 to do is say that when Mario jumps 756 00:35:31,746 --> 00:35:36,256 into this coin block we want a coin to appear. 757 00:35:36,256 --> 00:35:38,526 So we somehow need to detect 758 00:35:38,956 --> 00:35:41,736 if Mario has jumped into the coin block. 759 00:35:42,746 --> 00:35:47,436 So to do that we're going to say when the green flag is clicked, 760 00:35:47,946 --> 00:35:52,636 and we're going to use a forever loop, so what this says it 761 00:35:52,636 --> 00:35:56,426 that the entire time that the game is playing I'm going 762 00:35:56,426 --> 00:36:00,366 to be doing whatever is inside of this forever puzzle piece. 763 00:36:00,896 --> 00:36:05,566 So what we can say is if what? 764 00:36:05,736 --> 00:36:12,086 We want to detect if Mario is touching the block, 765 00:36:12,206 --> 00:36:13,826 so which of these blocks can we use? 766 00:36:14,516 --> 00:36:18,626 [ Inaudible ] 767 00:36:19,126 --> 00:36:19,386 >> Exactly. 768 00:36:19,386 --> 00:36:21,356 So we can use touching. 769 00:36:21,496 --> 00:36:24,386 We could also hypothetically say if distance to Mario is zero, 770 00:36:24,386 --> 00:36:25,386 or something like that, 771 00:36:25,836 --> 00:36:28,096 but that's just the same as if it's touching. 772 00:36:28,096 --> 00:36:30,926 In this drop down here we have Mario. 773 00:36:31,336 --> 00:36:34,156 We also could say built in are the mouse pointers, 774 00:36:34,156 --> 00:36:35,396 so wherever the user's mouse pointer is, 775 00:36:35,396 --> 00:36:37,456 that's how we did the [inaudible] cat in lecture 776 00:36:37,886 --> 00:36:40,256 or the edge, so if it's at the edge of the stage and you want 777 00:36:40,256 --> 00:36:42,516 to bounce off or something, that's built in there, too. 778 00:36:42,516 --> 00:36:45,676 But in this case we just want Mario. 779 00:36:46,306 --> 00:36:48,296 And so now let's just make sure this worked. 780 00:36:48,556 --> 00:36:53,476 We can just say well, let's say hello for two seconds. 781 00:36:54,676 --> 00:36:56,466 So here's my block over here. 782 00:36:57,076 --> 00:37:00,856 Let's just move it over to where that block is. 783 00:37:02,466 --> 00:37:06,936 And run our program so we can come 784 00:37:06,936 --> 00:37:10,066 over here, jump and there we go. 785 00:37:10,246 --> 00:37:11,836 We just hit our coin block. 786 00:37:12,346 --> 00:37:16,536 So you'll notice that up here there's this awkward Mario 787 00:37:16,566 --> 00:37:17,096 jump height. 788 00:37:17,686 --> 00:37:20,486 So remember that's what we called our jump height variable 789 00:37:20,696 --> 00:37:23,266 and we don't want that sitting up there 790 00:37:23,266 --> 00:37:25,196 because that's kind of odd. 791 00:37:25,196 --> 00:37:30,126 So if we go back into Mario, click over here to variables, 792 00:37:30,216 --> 00:37:34,146 you'll see a little checkmark next to jump height. 793 00:37:34,436 --> 00:37:37,486 And as soon as I click that, it's gone. 794 00:37:38,076 --> 00:37:40,226 So there we go. 795 00:37:40,926 --> 00:37:41,926 So now, yes? 796 00:37:41,926 --> 00:37:42,246 >> [Inaudible] 797 00:37:42,246 --> 00:37:47,526 >> What then does the hide variable command do? 798 00:37:47,526 --> 00:37:47,816 >> Yes. 799 00:37:47,816 --> 00:37:52,706 >> So that probably, oh, so that, you can dynamically do it. 800 00:37:52,706 --> 00:37:55,156 I could say when green flag clicked, hide the variable, 801 00:37:55,156 --> 00:37:56,636 and then it wouldn't be there anymore. 802 00:37:56,756 --> 00:37:58,776 Or I could, since I know I never want it there, 803 00:37:58,996 --> 00:38:00,226 I could just check that checkbox. 804 00:38:00,226 --> 00:38:00,336 Yes? 805 00:38:01,516 --> 00:38:06,286 [ Inaudible ] 806 00:38:06,786 --> 00:38:09,076 >> Yes. So this, so how do we copy 807 00:38:09,076 --> 00:38:11,456 and paste chunks between two scripts? 808 00:38:11,916 --> 00:38:14,746 So what we can do is let's say we want to duplicate this block, 809 00:38:14,906 --> 00:38:17,526 so I can right click it or double tap it on a Mac 810 00:38:17,866 --> 00:38:18,946 and I can click duplicate. 811 00:38:19,566 --> 00:38:20,456 So here it is again. 812 00:38:20,936 --> 00:38:22,286 So now let's put this back here. 813 00:38:22,516 --> 00:38:25,116 Now let's say that I wanted to somehow give this to Mario 814 00:38:25,116 --> 00:38:27,346 for some reason, I can just come over here to Mario, 815 00:38:28,216 --> 00:38:32,326 drop it down and here it is. 816 00:38:32,556 --> 00:38:35,746 So I just copy that script from block to Mario. 817 00:38:36,666 --> 00:38:38,776 So we can get rid of that. 818 00:38:38,776 --> 00:38:40,926 So to get rid of blocks, by the way, just drag them 819 00:38:40,926 --> 00:38:45,176 over to the left side and let go and they're gone. 820 00:38:45,386 --> 00:38:47,386 Having scripts not attached to anything 821 00:38:47,606 --> 00:38:50,156 like this will actually not affect your program 822 00:38:50,156 --> 00:38:50,926 or what's going on. 823 00:38:51,226 --> 00:38:53,236 But it's probably not that good of an idea 824 00:38:53,236 --> 00:38:54,266 to have them floating around. 825 00:38:54,356 --> 00:38:58,826 All right, so you'll notice here that we have several blocks. 826 00:38:59,686 --> 00:39:01,936 So let's just duplicate the single block. 827 00:39:03,356 --> 00:39:06,146 So duplicate, duplicate. 828 00:39:07,546 --> 00:39:11,606 So now let's move one over to this question mark and one 829 00:39:11,606 --> 00:39:13,786 over this question mark. 830 00:39:13,786 --> 00:39:17,686 So now you can see where having names other than sprite one 831 00:39:17,686 --> 00:39:19,636 and sprite two are pretty helpful because just looking 832 00:39:19,636 --> 00:39:21,566 at this I don't really know which block is which. 833 00:39:22,036 --> 00:39:24,946 So this is the left block, 834 00:39:25,016 --> 00:39:27,066 so let's just rename him to left block. 835 00:39:27,826 --> 00:39:31,896 This is the middle, this is the middle block 836 00:39:32,616 --> 00:39:38,126 and this is the right, so this is the right block. 837 00:39:39,156 --> 00:39:40,976 So now because I've duplicated them, 838 00:39:41,176 --> 00:39:42,286 they have the same scripts. 839 00:39:42,396 --> 00:39:45,686 So if I touch any one of these, hello, hello, hello. 840 00:39:45,686 --> 00:39:49,316 So you notice that these are all independent of each other. 841 00:39:49,316 --> 00:39:51,296 I can have two hellos up on the screen at once 842 00:39:51,576 --> 00:39:53,476 because I have multiple different sprites. 843 00:39:54,136 --> 00:39:56,936 So where Mario is just a single sprite with different costumes, 844 00:39:57,106 --> 00:39:58,796 this is actually two different sprites 845 00:39:59,086 --> 00:40:00,706 that can act independently of each other. 846 00:40:02,026 --> 00:40:02,326 Yes? 847 00:40:03,516 --> 00:40:16,136 [ Inaudible ] 848 00:40:16,636 --> 00:40:18,956 >> So is there a way to have multiple instances 849 00:40:18,956 --> 00:40:20,356 of the same sprite on the stage? 850 00:40:20,486 --> 00:40:23,266 That is thinking exactly like a computer scientist, but no, 851 00:40:23,596 --> 00:40:26,106 in scratch, unfortunately there is not. 852 00:40:26,106 --> 00:40:29,596 When we do actual programming, then that is exactly the way 853 00:40:29,596 --> 00:40:30,476 to be thinking about things. 854 00:40:30,476 --> 00:40:32,836 Can we reuse code and can we avoid having to copy 855 00:40:32,836 --> 00:40:33,896 and paste all over the place? 856 00:40:34,256 --> 00:40:37,616 Unfortunately in sprite we can't just because the script is kind 857 00:40:37,616 --> 00:40:38,866 of a container, I'm sorry, 858 00:40:38,866 --> 00:40:40,846 the sprite is a container for all the scripts. 859 00:40:41,176 --> 00:40:42,766 But this is the only week in which 860 00:40:42,766 --> 00:40:44,736 that will be the way things are. 861 00:40:46,466 --> 00:40:47,666 Other questions so far? 862 00:40:48,766 --> 00:40:48,956 Yes? 863 00:40:49,516 --> 00:41:01,806 [ Inaudible ] 864 00:41:02,306 --> 00:41:05,376 >> So I drag the coin boxes into place, will they stay there? 865 00:41:05,426 --> 00:41:08,966 Yes. So they're going to stay there until I say otherwise. 866 00:41:09,326 --> 00:41:11,586 In the case of Mario we need to reset his position 867 00:41:11,586 --> 00:41:12,786 because he's going to move around. 868 00:41:12,936 --> 00:41:14,796 But these blocks are never going to actually move, 869 00:41:14,836 --> 00:41:21,026 in this program anyway, so we can just leave them there. 870 00:41:21,026 --> 00:41:22,926 Okay, so now, one more question? 871 00:41:23,516 --> 00:41:29,586 [ Inaudible ] 872 00:41:30,086 --> 00:41:32,636 >> Talk about downloading? 873 00:41:32,636 --> 00:41:33,916 >> [Inaudible] 874 00:41:33,916 --> 00:41:37,396 >> Oh, so how I would like download Mario into my program? 875 00:41:38,516 --> 00:41:42,546 [ Inaudible ] 876 00:41:43,046 --> 00:41:43,446 >> Oh, okay. 877 00:41:43,446 --> 00:41:45,266 So yes, so if we just come over here 878 00:41:45,646 --> 00:41:50,856 to scratch.mit.edu we can just click 879 00:41:50,856 --> 00:41:52,546 on download scratch right here. 880 00:41:52,736 --> 00:41:55,346 [Inaudible] you can fill out the form. 881 00:41:55,956 --> 00:41:58,306 On windows this is going to download an installer 882 00:41:58,306 --> 00:42:01,586 so you can just double click it and click next until it's done. 883 00:42:01,586 --> 00:42:03,926 In Mac it's going to download what's called a DMG 884 00:42:03,926 --> 00:42:07,336 so you're just going to double click that and it's going 885 00:42:07,336 --> 00:42:09,106 to open up a little thing with the scratch logo 886 00:42:09,106 --> 00:42:10,596 and then your applications folder 887 00:42:10,596 --> 00:42:12,496 and you can just drag the little scratch pad 888 00:42:12,496 --> 00:42:14,816 into your applications folder and so then it'll be 889 00:42:14,816 --> 00:42:22,206 in applications and you can see scratch. 890 00:42:22,206 --> 00:42:35,566 So other logistical questions like that? 891 00:42:35,646 --> 00:42:35,916 Yes? 892 00:42:36,516 --> 00:42:38,576 [ Inaudible ] 893 00:42:39,076 --> 00:42:40,336 >> Yes, so instead of. 894 00:42:40,336 --> 00:42:40,403 >> [Inaudible] 895 00:42:40,403 --> 00:42:41,806 >> Yes, so instead of dragging the coin box, 896 00:42:41,806 --> 00:42:42,506 could I set it's location? 897 00:42:42,506 --> 00:42:43,546 Yes, exactly, I could have. 898 00:42:43,546 --> 00:42:45,936 I didn't, but I could certainly say set X to negative 55, 899 00:42:45,966 --> 00:42:47,736 negative 46 and that would be just as good a way to do this. 900 00:42:47,766 --> 00:42:47,976 Yes. Yes? 901 00:42:48,516 --> 00:42:52,546 [ Inaudible ] 902 00:42:53,046 --> 00:42:54,196 >> Oh, so sure, so you'll hear more 903 00:42:54,196 --> 00:42:56,106 about the submission instructions very shortly, 904 00:42:56,346 --> 00:42:57,416 but you're basically just going to go 905 00:42:57,416 --> 00:42:58,506 to a website and upload this. 906 00:42:59,426 --> 00:43:01,826 Yes. So nothing too complicated. 907 00:43:03,966 --> 00:43:05,436 Other questions? 908 00:43:05,696 --> 00:43:07,376 All right. 909 00:43:07,456 --> 00:43:09,926 So as Mario is jumping around and hitting all these blocks, 910 00:43:10,606 --> 00:43:12,326 maybe you want to keep track of a score. 911 00:43:12,876 --> 00:43:15,116 So what do you think we're going to need to use in order 912 00:43:15,116 --> 00:43:17,016 to keep track of what the player's score is? 913 00:43:17,016 --> 00:43:17,786 >> [Inaudible] 914 00:43:17,786 --> 00:43:19,246 >> A variable, exactly. 915 00:43:20,556 --> 00:43:25,646 So let's make a new variable. 916 00:43:25,646 --> 00:43:30,356 And so this time we want it to be available to all sprites 917 00:43:30,546 --> 00:43:33,136 because the score doesn't really pertain to just a single block 918 00:43:33,136 --> 00:43:35,696 or to Mario, so let's just call the variable score 919 00:43:36,106 --> 00:43:36,926 for all sprites. 920 00:43:37,606 --> 00:43:40,336 And now you'll notice that on block right we have score 921 00:43:40,696 --> 00:43:43,656 and on Mario we have both score and jump height. 922 00:43:44,176 --> 00:43:47,286 You can see this little divider line here and that says 923 00:43:47,356 --> 00:43:49,966 that these up here are for everyone and these 924 00:43:49,966 --> 00:43:52,016 down here are for just me. 925 00:43:52,736 --> 00:43:55,926 So when we start off we probably just want to set the score 926 00:43:56,406 --> 00:44:00,286 to zero and when we hit all of these blocks we just want 927 00:44:00,286 --> 00:44:02,886 to change the score by one. 928 00:44:03,726 --> 00:44:09,806 So we can drop that into all three of them. 929 00:44:09,986 --> 00:44:12,796 Change score by one. 930 00:44:13,076 --> 00:44:15,816 And so now as I run around you'll see 931 00:44:15,816 --> 00:44:21,576 that my score is going up. 932 00:44:22,566 --> 00:44:25,766 So questions on how we can add score 933 00:44:25,896 --> 00:44:27,486 or any other variable questions? 934 00:44:29,076 --> 00:44:32,026 All right yes? 935 00:44:33,516 --> 00:44:45,676 [ Inaudible ] 936 00:44:46,176 --> 00:44:48,286 >> So why do we need that green flag? 937 00:44:48,946 --> 00:44:51,696 So basically if there are puzzle pieces that aren't connected 938 00:44:51,696 --> 00:44:55,166 to like a wavy thing, those will just never be executed. 939 00:44:55,366 --> 00:44:57,456 So everything in scratch is triggered by an event. 940 00:44:58,516 --> 00:45:01,896 So the event is actually what starts everything connected 941 00:45:01,896 --> 00:45:03,696 to that puzzle piece from executing. 942 00:45:03,696 --> 00:45:05,016 So if it's not connected to any event, 943 00:45:05,276 --> 00:45:08,276 it's just never going to fire. 944 00:45:08,496 --> 00:45:09,356 Other questions so far? 945 00:45:09,556 --> 00:45:09,716 Yes? 946 00:45:10,516 --> 00:45:15,196 [ Inaudible ] 947 00:45:15,696 --> 00:45:17,116 >> So is there a way to cap it 948 00:45:17,236 --> 00:45:19,986 to just not hit the same block every time? 949 00:45:20,206 --> 00:45:21,826 So we could do something 950 00:45:21,826 --> 00:45:26,006 like each block have a variable that's like number of hits left. 951 00:45:26,526 --> 00:45:28,276 You can start that off at say 5. 952 00:45:28,736 --> 00:45:31,566 Every time you hit that block then maybe the score could go 953 00:45:31,566 --> 00:45:33,926 down one and if there are no hits left then you can't hit 954 00:45:33,926 --> 00:45:34,616 that block anymore. 955 00:45:34,916 --> 00:45:36,566 So that's one way of doing it. 956 00:45:36,566 --> 00:45:40,046 We could also say you know, Mario has like a maximum score 957 00:45:40,046 --> 00:45:43,376 of 10, so if he hits 10 blocks then he's hit the high score 958 00:45:43,376 --> 00:45:45,346 and he wins, or something like that. 959 00:45:45,436 --> 00:45:46,496 So yes, there's plenty 960 00:45:46,496 --> 00:45:49,046 of different ways you could implement something like that. 961 00:45:49,046 --> 00:45:51,386 The variables are going to come in really, really handy 962 00:45:51,386 --> 00:45:53,846 for things like how many, can I have a maximum number 963 00:45:53,846 --> 00:45:54,946 of times I can do this 964 00:45:54,946 --> 00:45:56,726 or how many times should I execute this loop 965 00:45:56,896 --> 00:45:58,406 or something like that. 966 00:46:00,966 --> 00:46:02,006 Other questions? 967 00:46:02,536 --> 00:46:04,366 All right. 968 00:46:04,486 --> 00:46:05,976 So one last thing. 969 00:46:06,546 --> 00:46:11,746 Let me just open up the final project instead of doing this 970 00:46:11,746 --> 00:46:15,026 by hand because it's kind of long. 971 00:46:15,106 --> 00:46:18,076 So I'm just opening a scratch project 972 00:46:18,076 --> 00:46:19,896 that I've already created beforehand. 973 00:46:20,356 --> 00:46:24,356 And so this is kind of the final version of Mario. 974 00:46:25,066 --> 00:46:28,096 And so let's just go over a few other things. 975 00:46:29,166 --> 00:46:32,066 So you'll notice when I play this version I have a timer 976 00:46:32,256 --> 00:46:34,686 up here in the top left and the timer is counting down 977 00:46:35,186 --> 00:46:41,066 and once the timer finishes, 3, 2, 1, so the game is over. 978 00:46:41,066 --> 00:46:42,936 And now even though I'm pressing the left arrow 979 00:46:42,936 --> 00:46:44,316 and the right arrow, you can see them lighting 980 00:46:44,316 --> 00:46:46,496 up over here, Mario is not moving. 981 00:46:47,166 --> 00:46:49,306 So let's take a look at how we would do something like that. 982 00:46:50,046 --> 00:46:53,656 So we're going to want to have a timer variable, of course. 983 00:46:54,066 --> 00:46:59,276 So to do that I just said make a variable, call it timer, 984 00:46:59,376 --> 00:47:06,206 and over here we're setting timer to some random number. 985 00:47:06,206 --> 00:47:09,876 So in the case you just saw it was 8, 986 00:47:10,206 --> 00:47:16,736 if I click it again, it's 1, good game. 987 00:47:17,716 --> 00:47:21,516 So now what I've done is I have this forever loop and I'm saying 988 00:47:21,516 --> 00:47:25,466 if the timer is zero, so that means the game has run out, 989 00:47:26,516 --> 00:47:29,846 I'm setting this other variable called can move to zero, 990 00:47:30,376 --> 00:47:32,536 which originally is set to one. 991 00:47:33,096 --> 00:47:34,846 So this variable is effectively a flag. 992 00:47:35,446 --> 00:47:38,546 If the flag is raised I can move around, but as soon as time runs 993 00:47:38,546 --> 00:47:39,916 out I'm kind of lowering the flag 994 00:47:39,916 --> 00:47:41,336 and saying you can't move anymore. 995 00:47:42,076 --> 00:47:45,496 So you'll notice in each of my arrow things I've said 996 00:47:45,946 --> 00:47:49,196 if can move is one, which means the same thing 997 00:47:49,196 --> 00:47:53,186 as if the timer is greater than zero then I move around. 998 00:47:54,046 --> 00:47:57,246 So if can move is zero, then I'm not going to move around. 999 00:47:57,306 --> 00:47:59,656 So that's why once Mario is finished he's not going 1000 00:47:59,656 --> 00:48:00,486 to move around anymore. 1001 00:48:00,986 --> 00:48:05,576 And we also have these little coins that pop 1002 00:48:05,576 --> 00:48:07,496 up when you hit the blocks. 1003 00:48:07,496 --> 00:48:13,066 So to do that, I've created another sprite called coin. 1004 00:48:13,066 --> 00:48:16,616 And in here this is just why I didn't want 1005 00:48:16,616 --> 00:48:17,876 to do it [inaudible] a little complicated, 1006 00:48:18,376 --> 00:48:20,356 but we're using messages now. 1007 00:48:21,266 --> 00:48:23,906 So we don't want the coin to always be there. 1008 00:48:23,986 --> 00:48:26,706 So as soon as the green flag is clicked the coin is going 1009 00:48:26,706 --> 00:48:27,096 to hide. 1010 00:48:28,076 --> 00:48:32,306 So I could have had, like with my blocks, a left coin, 1011 00:48:32,306 --> 00:48:33,516 a middle coin and a right coin, 1012 00:48:34,406 --> 00:48:36,946 but in this case we're only going to have one coin 1013 00:48:36,946 --> 00:48:38,066 on the screen at a time. 1014 00:48:38,566 --> 00:48:40,726 So I could just have one sprite and set 1015 00:48:40,726 --> 00:48:43,336 in it's position depending on which block was hit. 1016 00:48:44,166 --> 00:48:45,906 So how do I know which block was hit? 1017 00:48:46,636 --> 00:48:50,176 Well in each of these block sprites I'm now broadcasting a 1018 00:48:50,176 --> 00:48:52,666 message and I said coin appear left. 1019 00:48:53,216 --> 00:48:54,866 So I'm telling the coin I want you 1020 00:48:54,866 --> 00:48:56,726 to appear over the left block. 1021 00:48:57,656 --> 00:49:00,536 If I click this down arrow you can see all the other messages 1022 00:49:00,536 --> 00:49:03,056 I've created, in this case one for each block. 1023 00:49:03,466 --> 00:49:06,246 Now if I click new I can create a new message, 1024 00:49:06,246 --> 00:49:08,496 which is what I did when I typed in coin appear left, 1025 00:49:08,836 --> 00:49:10,486 middle and right, each of these times. 1026 00:49:11,636 --> 00:49:12,906 So still [inaudible] touching Mario, 1027 00:49:13,266 --> 00:49:15,476 we're going to broadcast this message. 1028 00:49:15,946 --> 00:49:19,036 Now you'll notice that coin is going to respond 1029 00:49:19,256 --> 00:49:20,526 to each of these messages. 1030 00:49:20,906 --> 00:49:23,366 So now we're just doing something very similar 1031 00:49:23,366 --> 00:49:23,946 to jumping. 1032 00:49:23,946 --> 00:49:26,366 We're going to do is we're going to change the score by one, 1033 00:49:26,366 --> 00:49:29,766 so the score goes up and now notice we're still hidden, 1034 00:49:30,156 --> 00:49:32,906 right, because I said hide when the green flag is clicked. 1035 00:49:33,146 --> 00:49:36,216 So I'm still hidden and then I changed the position 1036 00:49:36,216 --> 00:49:36,696 of the coin. 1037 00:49:37,186 --> 00:49:40,396 So I'm saying go to the X position of the left block. 1038 00:49:40,856 --> 00:49:41,876 So that's going to put it right 1039 00:49:41,876 --> 00:49:43,666 over the middle of the left block. 1040 00:49:44,536 --> 00:49:48,996 And then the Y position is a little bit higher than the block 1041 00:49:49,186 --> 00:49:51,766 so that it doesn't appear over the block and then animate up. 1042 00:49:52,046 --> 00:49:55,556 And then after I set the position I'm going to show it. 1043 00:49:55,556 --> 00:49:58,946 So that means the coin isn't going to be kind of flying 1044 00:49:58,946 --> 00:50:02,266 around weirdly but it's going to be there before it shows. 1045 00:50:02,846 --> 00:50:04,456 So then we're getting a similar thing to jumping. 1046 00:50:04,456 --> 00:50:08,606 We're just going to glide up and then we're going to hide it 1047 00:50:08,826 --> 00:50:10,726 because the coin is done animating. 1048 00:50:11,656 --> 00:50:13,866 So that gives the final effect. 1049 00:50:15,236 --> 00:50:18,236 The coin appearing up and then hiding. 1050 00:50:18,236 --> 00:50:19,586 So you notice I can only have one 1051 00:50:19,766 --> 00:50:21,506 at a time even though I'm kind of touching both 1052 00:50:21,506 --> 00:50:23,256 of these blocks right here and that's 1053 00:50:23,326 --> 00:50:26,006 because I only have one coin sprite. 1054 00:50:27,056 --> 00:50:28,896 So any final questions? 1055 00:50:29,246 --> 00:50:29,476 Yes? 1056 00:50:30,516 --> 00:50:35,016 [ Inaudible ] 1057 00:50:35,516 --> 00:50:39,376 >> So do we have to write any code to decrease the timer? 1058 00:50:39,376 --> 00:50:41,206 Yes. I probably should have showed you that. 1059 00:50:41,916 --> 00:50:45,006 So yes, so if the timer is zero that means I'm done. 1060 00:50:45,136 --> 00:50:46,636 I don't want to decrease the timer anymore. 1061 00:50:47,016 --> 00:50:50,376 But else if the timer is not zero then I want 1062 00:50:50,376 --> 00:50:53,866 to wait a second and then subtract one from the timer. 1063 00:50:54,536 --> 00:50:56,996 So if I didn't have this wait one second the game would just 1064 00:50:56,996 --> 00:50:57,706 be over immediately. 1065 00:50:57,706 --> 00:51:00,066 It would just subtract one a bunch of times really fast 1066 00:51:00,136 --> 00:51:00,956 and it would be game over. 1067 00:51:01,406 --> 00:51:03,646 So instead we want to say okay, wait a second 1068 00:51:03,646 --> 00:51:06,776 and then decrease it so we have this countdown effect. 1069 00:51:07,116 --> 00:51:08,626 So yes, that was a good question 1070 00:51:08,626 --> 00:51:10,726 and then I totally forgot about that. 1071 00:51:12,086 --> 00:51:13,096 Other questions? 1072 00:51:13,606 --> 00:51:13,726 Yes? 1073 00:51:13,726 --> 00:51:15,196 >> [Inaudible] 1074 00:51:15,196 --> 00:51:20,696 >> Is there an undo key? 1075 00:51:20,806 --> 00:51:21,756 That's a good question. 1076 00:51:21,756 --> 00:51:24,846 Well there's undelete, that's cool. 1077 00:51:26,336 --> 00:51:31,986 Like if I disconnect this and I do edit, nope, command z, nope. 1078 00:51:31,986 --> 00:51:35,096 You can undelete, but you can't undo anything else. 1079 00:51:35,096 --> 00:51:37,546 But deletes the important one anyway. 1080 00:51:38,826 --> 00:51:39,216 Yes? 1081 00:51:40,516 --> 00:51:44,546 [ Inaudible ] 1082 00:51:45,046 --> 00:51:46,746 >> Yes. So messages are different than variables. 1083 00:51:47,516 --> 00:51:50,746 [ Inaudible ] 1084 00:51:51,246 --> 00:51:53,576 >> So if I wanted to create a new message this time I don't 1085 00:51:53,576 --> 00:51:55,936 have to come over here and say make a new message or something. 1086 00:51:56,226 --> 00:52:01,156 Instead when I drag in this broadcast block I can come 1087 00:52:01,156 --> 00:52:03,016 down here to new and it's going 1088 00:52:03,056 --> 00:52:04,936 to ask me what I want my message to be called. 1089 00:52:05,266 --> 00:52:09,106 And I can say whatever, and so now that's in my list 1090 00:52:09,206 --> 00:52:12,956 of all my messages and now if I'm another sprite, 1091 00:52:12,956 --> 00:52:16,686 I want to respond to it, I can say control and then 1092 00:52:17,346 --> 00:52:21,316 when I receive and then here's the message I just created. 1093 00:52:22,426 --> 00:52:27,226 So as soon as like nothing is using some message then it's 1094 00:52:27,226 --> 00:52:28,646 going to disappear from the list. 1095 00:52:28,926 --> 00:52:33,276 So if I get rid of this and then go back over to here 1096 00:52:33,276 --> 00:52:34,866 and say broadcast coin appear left, 1097 00:52:35,376 --> 00:52:39,436 now that other message I created isn't being used here so in my 1098 00:52:39,436 --> 00:52:41,116 when I receive it's just gone. 1099 00:52:41,766 --> 00:52:42,786 So scratch is just smart enough 1100 00:52:42,786 --> 00:52:44,186 to say it's not being used anymore, 1101 00:52:44,186 --> 00:52:44,886 let's just get rid of it. 1102 00:52:45,736 --> 00:52:45,826 Yes? 1103 00:52:46,516 --> 00:52:50,236 [ Inaudible ] 1104 00:52:50,736 --> 00:52:55,626 >> Sure. So all the timer logic is occurring inside of Mario. 1105 00:52:55,926 --> 00:52:57,706 So this could also be something that's going to occur 1106 00:52:57,706 --> 00:53:00,286 in the stage because it doesn't really pertain to anything. 1107 00:53:00,286 --> 00:53:02,056 In this case it's in Mario. 1108 00:53:02,776 --> 00:53:05,366 So the first thing I do is click make a variable. 1109 00:53:05,746 --> 00:53:08,526 So over here, make a variable, I'm going to say timer 1110 00:53:08,526 --> 00:53:10,266 and then it's going to appear hear. 1111 00:53:10,736 --> 00:53:14,346 So the checkbox is there and you'll notice 1112 00:53:14,346 --> 00:53:15,706 that it doesn't actually say timer. 1113 00:53:16,106 --> 00:53:18,436 That if I just click it, I lied. 1114 00:53:18,846 --> 00:53:26,566 If I click, there we go, so if I double click it I can actually 1115 00:53:26,566 --> 00:53:28,406 change what it says. 1116 00:53:28,406 --> 00:53:30,276 So if I click normal read out, it's going to say that. 1117 00:53:30,626 --> 00:53:33,396 In this case I clicked large read out so I got rid 1118 00:53:33,396 --> 00:53:35,496 of the text where the text is there on the score. 1119 00:53:35,696 --> 00:53:37,566 So that's all I did to create 1120 00:53:37,566 --> 00:53:38,976 that little block on the top left. 1121 00:53:39,616 --> 00:53:42,616 So now all the timer logic is occurring right here. 1122 00:53:43,396 --> 00:53:46,006 So first I need to start the timer off at some value, 1123 00:53:46,476 --> 00:53:48,936 so I'm just starting it off in a random value from one to 10 1124 00:53:49,336 --> 00:53:51,106 on just because I like the random block. 1125 00:53:51,866 --> 00:53:55,106 And now I'm entering into a forever loop. 1126 00:53:55,436 --> 00:53:59,246 So what's inside of this piece is going to occur forever 1127 00:53:59,246 --> 00:54:01,816 as long as the user is playing the game. 1128 00:54:01,856 --> 00:54:03,666 So first you want to check the value of the timer. 1129 00:54:04,116 --> 00:54:06,776 If the timer is done, we don't want to keep decreasing it 1130 00:54:06,776 --> 00:54:07,786 because the it will be negative. 1131 00:54:08,756 --> 00:54:10,496 And when the timer is done we also want 1132 00:54:10,496 --> 00:54:12,536 to tell Mario you can't move around anymore 1133 00:54:12,536 --> 00:54:13,506 and just say game over. 1134 00:54:14,166 --> 00:54:17,216 So if the timer is not equal to zero and we know 1135 00:54:17,216 --> 00:54:21,546 that the timer can never be negative, no it can be negative, 1136 00:54:21,546 --> 00:54:24,236 that's okay, so if the timer is not zero, 1137 00:54:24,236 --> 00:54:26,396 in this case it's some value 1138 00:54:26,926 --> 00:54:28,506 that means there's time remaining in a game, 1139 00:54:29,076 --> 00:54:30,706 then we're going to wait a second 1140 00:54:31,096 --> 00:54:33,366 because if we don't wait the timer is just going 1141 00:54:33,366 --> 00:54:36,336 to decrease really fast because we're not telling the computer 1142 00:54:36,336 --> 00:54:37,876 that we want to decrease it. 1143 00:54:38,716 --> 00:54:41,326 So then we want to change the timer by one 1144 00:54:41,696 --> 00:54:45,126 so every one second this is going 1145 00:54:45,126 --> 00:54:46,966 to decrease the timer by one. 1146 00:54:48,326 --> 00:54:50,526 So just because we have a forever loop here 1147 00:54:51,856 --> 00:54:54,106 that doesn't mean that neither of these can execute. 1148 00:54:54,866 --> 00:54:57,706 Because these have different starting points they can execute 1149 00:54:57,706 --> 00:54:59,516 independently of each other, right? 1150 00:54:59,516 --> 00:55:02,756 Normally if I had, if I could put a puzzle piece 1151 00:55:02,756 --> 00:55:04,986 down here it would never be reachable 1152 00:55:05,046 --> 00:55:07,156 because this is never going to stop. 1153 00:55:07,716 --> 00:55:10,106 But because these are connected to different starting pieces, 1154 00:55:10,526 --> 00:55:12,906 just because this is forever that doesn't mean 1155 00:55:12,906 --> 00:55:14,286 that this won't work anymore. 1156 00:55:15,706 --> 00:55:18,866 So I can also have multiple when green flag clicks 1157 00:55:18,866 --> 00:55:21,426 in case you ever run into that forever problem. 1158 00:55:21,616 --> 00:55:27,216 So is that clear how that timer works? 1159 00:55:27,216 --> 00:55:27,376 >> [Inaudible] 1160 00:55:27,376 --> 00:55:30,866 >> So this can move is just saying effectively is there time 1161 00:55:30,946 --> 00:55:31,786 left in the game? 1162 00:55:32,166 --> 00:55:35,616 So if there is time left in the game it's the value one. 1163 00:55:35,996 --> 00:55:37,416 So one often means true. 1164 00:55:37,416 --> 00:55:39,016 So yes, I can move around. 1165 00:55:39,286 --> 00:55:43,486 And only if I can move around am I going to actually respond 1166 00:55:43,756 --> 00:55:45,896 to jumping, moving left and moving right. 1167 00:55:46,466 --> 00:55:50,136 So when the game is over we're going to say can't move anymore, 1168 00:55:50,336 --> 00:55:53,716 it's zero, so that means when I'm back up here, 1169 00:55:53,866 --> 00:55:54,946 this will never execute. 1170 00:55:55,056 --> 00:55:57,316 Does that make sense? 1171 00:55:57,316 --> 00:55:58,796 >> [Inaudible] 1172 00:55:58,796 --> 00:56:05,166 >> And how do I get the timer to run? 1173 00:56:05,166 --> 00:56:05,316 >> [Inaudible] 1174 00:56:05,316 --> 00:56:07,996 >> So right down here I'm actually saying change timer 1175 00:56:07,996 --> 00:56:11,696 by negative one every one second, effectively. 1176 00:56:12,156 --> 00:56:14,496 So forever, so when the game starts, 1177 00:56:14,496 --> 00:56:16,836 we're going to say set everything, set Mario, 1178 00:56:16,836 --> 00:56:18,066 and we're going to enter this forever loop. 1179 00:56:18,486 --> 00:56:20,916 So timer is not zero definitely, 1180 00:56:20,916 --> 00:56:22,596 because I'm taking a value from one to 10. 1181 00:56:22,946 --> 00:56:24,746 So if timer is zero, it's not, so we're going 1182 00:56:24,746 --> 00:56:25,826 to jump down here to else. 1183 00:56:26,156 --> 00:56:28,016 So this block is going to wait a second. 1184 00:56:29,016 --> 00:56:31,686 After it waits a second it's going to decrement the timer. 1185 00:56:31,876 --> 00:56:33,886 So if it was at 10, now it's at 9. 1186 00:56:34,526 --> 00:56:36,246 Now we're going to go back up here to forever. 1187 00:56:36,636 --> 00:56:39,986 If it's zero, it's not, come down here, okay, wait a second, 1188 00:56:40,616 --> 00:56:43,776 now it's 8, until timer is now zero, 1189 00:56:43,776 --> 00:56:45,456 we've decremented it from one to zero. 1190 00:56:46,016 --> 00:56:49,686 It's not a zero, oh, it is, so we're going to set this to zero 1191 00:56:49,686 --> 00:56:51,156 and we're going to say game over. 1192 00:56:55,956 --> 00:56:57,916 Are there any last, yes? 1193 00:56:58,516 --> 00:57:01,576 [ Inaudible ] 1194 00:57:02,076 --> 00:57:05,396 >> So can we also change the appearance of the screen just 1195 00:57:05,526 --> 00:57:09,906 as we did to the sprites? 1196 00:57:12,116 --> 00:57:14,426 We, do, yes so inside of stage 1197 00:57:15,386 --> 00:57:18,366 over in the looks tab we have switch to background. 1198 00:57:18,876 --> 00:57:21,696 You notice that we named these different backgrounds. 1199 00:57:22,516 --> 00:57:23,946 And so if we just use that switch 1200 00:57:23,946 --> 00:57:25,476 to background block we can do that. 1201 00:57:25,546 --> 00:57:27,526 So if we want to change the stage based 1202 00:57:27,526 --> 00:57:30,486 on something Mario did, how would we tell the stage 1203 00:57:30,636 --> 00:57:31,546 to change it's background? 1204 00:57:32,516 --> 00:57:37,476 [ Inaudible ] 1205 00:57:37,976 --> 00:57:40,056 >> Yes. The stage would say switch to costume, 1206 00:57:40,056 --> 00:57:42,026 but how does the stage know to do that? 1207 00:57:43,266 --> 00:57:43,356 Yes? 1208 00:57:43,356 --> 00:57:43,796 >> [Inaudible] 1209 00:57:43,796 --> 00:57:45,486 >> Exactly, so you'd broadcast a message. 1210 00:57:45,536 --> 00:57:48,206 So from Mario I'm going to broadcast stage white 1211 00:57:48,556 --> 00:57:51,006 and in stage I can say when I receive stage white, 1212 00:57:51,406 --> 00:57:54,366 switch to background one or whatever you called it. 1213 00:57:55,126 --> 00:57:55,336 Yes? 1214 00:57:55,336 --> 00:57:55,736 >> [Inaudible] 1215 00:57:55,736 --> 00:58:02,766 >> Oh, so how do I have it so Mario doesn't walk 1216 00:58:02,766 --> 00:58:03,156 through the pipe [inaudible]? 1217 00:58:03,156 --> 00:58:05,876 And so how would you? 1218 00:58:06,406 --> 00:58:08,046 So we could say a couple of things. 1219 00:58:08,146 --> 00:58:11,756 I could say make this a sprite just like we did 1220 00:58:11,756 --> 00:58:12,986 with the blocks, and I could say 1221 00:58:12,986 --> 00:58:15,206 if I'm touching the pipe then don't go right anymore. 1222 00:58:15,736 --> 00:58:19,516 Or I can, in Mario say if my X coordinate is greater than, 1223 00:58:19,876 --> 00:58:22,486 I don't know, like 194, then don't go forward anymore. 1224 00:58:22,836 --> 00:58:26,696 But basically it's going to boil down to using this sensing tab. 1225 00:58:26,696 --> 00:58:27,556 You could say touching. 1226 00:58:27,556 --> 00:58:29,136 You could even get really fancy and say 1227 00:58:29,136 --> 00:58:31,086 if you're touching the green color then don't touch it, 1228 00:58:31,446 --> 00:58:33,016 then don't move forward anymore. 1229 00:58:33,656 --> 00:58:35,566 But it's basically going to boil down to this sensing. 1230 00:58:35,566 --> 00:58:36,276 Where is Mario? 1231 00:58:36,276 --> 00:58:36,836 Where is the pipe? 1232 00:58:37,136 --> 00:58:38,736 Are they in a place where they shouldn't be? 1233 00:58:39,516 --> 00:58:43,976 [ Inaudible ] 1234 00:58:44,476 --> 00:58:46,516 >> So is the same thing true for the bottom blocks? 1235 00:58:46,586 --> 00:58:50,286 In this case we just never allow his Y coordinate to get lower 1236 00:58:50,846 --> 00:58:53,696 because up is going to go up and down a fixed amount 1237 00:58:53,696 --> 00:58:55,266 and then left and right isn't going to affect 1238 00:58:55,486 --> 00:58:58,196 where he is vertically, but you could do the same thing, yes. 1239 00:58:58,196 --> 00:59:00,816 You could say well if Mario's Y is lower 1240 00:59:00,816 --> 00:59:03,276 than something then just stop moving or something like that. 1241 00:59:03,536 --> 00:59:06,506 But yes, the same principle, you want to sense where objects are 1242 00:59:06,716 --> 00:59:08,736 and if two things are touching that shouldn't be, 1243 00:59:08,736 --> 00:59:11,506 just kind of adjust them where they're not. 1244 00:59:12,496 --> 00:59:12,976 Yes? 1245 00:59:13,516 --> 00:59:19,686 [ Inaudible ] 1246 00:59:20,186 --> 00:59:22,196 >> Yes, is there a way to make Mario jump in an arc? 1247 00:59:22,426 --> 00:59:25,646 There is. And basically you could do that, 1248 00:59:26,356 --> 00:59:28,216 you basically need to modify how we're doing this. 1249 00:59:28,216 --> 00:59:31,026 You probably need to use a loop, but you wouldn't want to say go 1250 00:59:31,026 --> 00:59:32,716 to the X position, you'd want to say go 1251 00:59:32,716 --> 00:59:35,816 to some x position plus some variable and then modify 1252 00:59:35,816 --> 00:59:37,706 that variable based on where he is in the jump. 1253 00:59:38,186 --> 00:59:38,306 Yes? 1254 00:59:38,306 --> 00:59:40,256 >> [Inaudible] 1255 00:59:40,256 --> 00:59:45,486 >> So how did I prevent the timer 1256 00:59:45,566 --> 00:59:48,146 from going down super fast? 1257 00:59:48,146 --> 00:59:50,306 I just said wait one second. 1258 00:59:51,046 --> 00:59:52,456 So that'll just make sure 1259 00:59:52,456 --> 00:59:53,966 that the timer doesn't go down anymore. 1260 00:59:56,336 --> 00:59:57,496 Last questions. 1261 00:59:57,496 --> 01:00:00,416 We're kind of running out of time. 1262 01:00:00,536 --> 01:00:00,736 All right. 1263 01:00:00,736 --> 01:00:02,826 So feel free to come talk to me afterwards. 1264 01:00:02,826 --> 01:00:03,406 I'll be here. 1265 01:00:03,406 --> 01:00:06,646 Also the CS50 help boards, feel free to post questions there 1266 01:00:06,646 --> 01:00:08,546 and get a really fast response time. 1267 01:00:08,546 --> 01:00:11,036 Remember these happen every week at this time in this room 1268 01:00:11,226 --> 01:00:12,646 for every problem set. 1269 01:00:12,646 --> 01:00:14,066 So good luck on scratch. 1270 01:00:15,516 --> 01:00:24,310 [ Applause ]