Go to the Scratch website: scratch.mit.edu
Follow the video instructions to practice making a catch game in Scratch. The Transcript below is a resource to find different sections of the directions in the video as needed.
TRANSCRIPT:
First, let's pick the character or object that you want to be catching things,
0:28
You can just click this button that says, Choose a Sprite, and you can pick anything you want. I will use a bowl.
0:34
Let's add a backdrop too. I'll use the boardwalk.
0:39
So, we want the bowl to be able to move side to side with the arrow keys so that it can catch whatever's going to be falling.
0:44
We can use this block and change X by 10 to make the ball go this way.
0:49
Let's make the ball do this if the right arrow key is pressed.
0:53
There's a really helpful block for this, which is an if then block.
0:57
In case you haven't seen an if then block before, here's how they work.
1:00
So in this example, if the cat is touching the mouse pointer it will play the sound, meow, but if it's not touching the mouse pointer, it won't play any sound.
1:12
So in our game, if the right arrow key is pressed, we can make the bowl change X by 10.
1:24
Let's try it out, and let's make it start when I click the green flag.
1:28
So, I'm pressing the right arrow key but nothing is happening.
1:32
That's because this if then block is only being checked once.
1:36
So, we can just put this inside a forever loop. And now, now this is what we want. It's always checking, is the right arrow key being pressed?
1:52
And to make the bowl go to the left, instead of changing X by 10, we can change X by -10.
1:59
Let's make it do this, if the left arrow key is pressed. And let's put this in the forever loop too.
2:07
There we go, now we have a catcher that we can move with the arrow keys.
2:12
Next, let's pick the object that we want to be falling and make it go to the top of the screen.
2:16
You can use any object you want. I'll use the apple.
2:20
At the beginning of the game, We want the apple to start at a random place at the top.
2:23
This block, go to random position, will make it go to a random place.
2:29
And this block, set Y, can set how high up a Sprite is. In Scratch, Y represents how far a Sprite is from the bottom of the screen to the top of the screen.
2:36
So if we set Y to zero, the apple goes up to about the middle. If we set Y at 20, it goes up a little higher, and 180 makes it go all the way to the top.
2:43
Now, if we make the apple go to a random position and then set Y to 180, it goes to a random place
but then Y is always set to be at the top, And that's just what we want.
2:52
When the game starts, it starts at a random place at the top of the screen.
3:00
Now, let's make our apple fall down. If we change, Y by 10, the apple goes upwards. To make it go down, we can put in a negative number.
3:04
And if we put this inside a forever loop, it'll keep falling until it hits the bottom. But now it's stuck.
3:13
So right now, we have an apple that can fall one time, what we would like it to do is if it's at the bottom, it goes to the top. This is another good time to use an if then block.
3:19
So let's drag one out. In here, we need to put some code that checks if the apple is at the bottom.
3:27
Now, how can we tell if the apple is at the bottom? Well, remember how I said that Y represents how high up a Sprite is, let's look at the apple's Y while it's falling.
3:34
Its Y position starts at 180, then it goes to 170, 160, it gets to zero, then it goes to -10, -20. And then down here, it's like -170.
3:43
So what we can test in here is, we can just check if the Y position of the apple
3:52
we can just check if the Y position of the apple is less than -170, because if the apple's Y position is that low, then we know it must be at the bottom.
3:54
So to test that, we can drag out this round blue block that says "Y position" and drag out the green "less than" block from the operator's category.
4:04
This block just checks if the thing on this side is less than the thing on this side.
4:13
We want to check if Y is less than -170. So we can put Y on this side and write -170.
4:17
Now, if the apple is at the bottom, what do we want it to do?
4:23
Well, we want it to go back up to the top, and we actually already have the code for that because we wrote it right here.
4:26
So, let's just put a copy of that same code in here. And let's put this code inside our forever loop.
4:32
So every time the apple moves down by -5, it asks, am I at the bottom?
4:38
Now we have an apple that can fall, and when it gets to the bottom, it goes back up to the top.
4:42
Now, let's make it so that we can actually catch the apples instead of them just falling through the bowl.
4:47
If the apple touches the bowl, then the player caught it. So it should stop falling and go back to the top somewhere else so it can start falling again.
4:52
So, this is another good time for an if-then block. There's this helpful block that says "touching mouse pointer," and instead of "mouse pointer," I can choose "bowl."
5:00
And now this block will test if the apple is touching the bowl. And if the apple is touching the bowl,
we want it to go back to the top.
5:07
And again, that's just our same code from before that makes it go to the top. Let's put this inside a forever loop, and let's make it play a sound when we catch it.
5:15
Nice. Lastly, let's add a score so that you get points for every apple you catch. To make a score, We can add a variable. If you haven't seen this before, a variable lets you keep track of a certain number in your project.
5:25
So, we can make a variable called Score and use it to keep track of how many points we've scored. We can use this change score by one block to make the score increase, to make the score increase,
and we can put this block here so every time we catch the apple, the score increases by one.
5:39
And when the game starts, let's set the score to zero. So it resets, there we go. That's a catch game.
Anyway, that's basically what I wanted to show you today.
5:56
I love catch games because I feel like they can be any type of game based on the objects that are falling and the character or the object that's catching them, and the backdrop you choose.
6:04
You could be catching pieces of trash to keep an ocean clean, or a pet could be catching treats, or just really anything. I'm so excited to see all the things you make.
6:12
Created by: Aimie McKenzie-Smith ~ Contact: amckenziesmith@njcu.edu