字幕表 動画を再生する 英語字幕をプリント Allison:Hey guys! I was just testing out the game I made. It's super easy to make simple games like this. And, in fact, I'll show you how I made it right now. Let's head on over to www.scratch.mit.edu. We want to create a new project, so lets click on the Create tab. I've already got a product opened, so we're going to switch over here. >> Let's start with a quick tour of the scratch environment. On the bottom left here, we have all the sprites that will be used in our game. For example, we have a monkey, banana, and broccoli. When we click on each sprite you'll notice that the right column will change, to show us that we're working with that specific sprite. Anything we put in this column will control the sprite that's highlighted. Here in the middle, we have our column containing our pallet a puzzle pieces, which we'll use to create our game. At the top, we have the category of puzzle pieces we have to work with. For example, the blue pieces, under the Motion tab, will allow us to control how our sprites move. We'll explore the other categories as we create our game. Finally, on the top left, we have our stage, where we'll actually play our game. Where we can see the effects of our scripts on the sprites. >> So let's get started. In our game, the monkey will try to eat the banana while avoiding the broccoli. The monkey will follow our mouse, and the broccoli and banana will float around the stage randomly. When the monkey gets close to the banana, the banana will actively try to avoid the monkey, just to make things a bit more exciting. >> Let's start by scripting the behavior of our main character, the monkey. To start our script, we'll use the When Green Flag clicked piece from the events category. Here. This will cause all puzzle pieces connected to the button to run when we click the Green Flag, here, at the top right of the stage. We want the monkey to follow the mouse. So we choose the Go To button and select Mouse Pointer, like so. So we're going to try it here. Let's test is and see what happens. >> So it seems like the monkey really only followed the first mouse click. This is because, by default, the Go To block only executes once. To get the monkey to follow the mouse throughout the entire game, we need this block to execute over and over again. Sounds like we need some kind of looping construct. So lets move into Control. Look, let's try this Forever loop. Seems like it works. >> So, next we should think about how the monkey will interact with other sprites. Basically, we need to add logic to our game, such that, the game will end if the monkey touches the banana or the broccoli. And actually use the word "if" when describing the behavior we're trying to create. And conveniently enough, there's a control blocked called If that we use for exactly this purpose. So the diamond shape, right here, on the block, is where we put the condition that we want to check. In this case, we'll check whether the monkey is touching the banana. >> Se we grab the Touching piece from the Sensing category. And choose Banana from the drop down menu. Now we have to tell our sprite what to do when it touches the banana. We want the game to end, and the monkey to say, you've won. So we add in a Say and Stop All piece. We'll change, hello, to, you won. And the time to 0.5. Now, we'll apply the same logic when the monkey is touching the broccoli, except we'll have the monkey say, you lost, instead of, you won. >> Let's test this out and see if it works. Awesome. We've finished scripting the monkey's behavior, but we're not done yet. We still have to tell the broccoli and banana what to do. >> Let's start with the simpler of the two, the broccoli. Which just needs to move randomly. Again, we'll begin with the When Green Flag clicked piece. We need the sprite to be in constant motion, so let's drag out the Forever loop. We'll create a random motion using some motion pieces with a random number generator. >> Alright, let's test this out. Awesome >> OK, now only the banana is left. Let's start off with the same set of pieces as before. So if the monkey gets close, the banana should avoid it. Else, the banana should move randomly. Sounds like a job for this If Else block. In the condition, we will check the bananas distance from the monkey, and then have it avoid accordingly. >> Now, when this condition doesn't apply, the banana should move randomly. So let's just steal our random motion pieces from the broccoli. All we have to do is drag the pieces we want to the banana sprite, and they'll be copied over. >> All done. Let's test it out. Awesome. Everything seems to be working. Now go and make your own games. >> If you need some inspiration check out past projects from CS50 on the website. >> My name is Allison, and this CS50. >> I need to get these set up super quick.