Blocks in Scratch from scratch – learning for children 8-9 years old and older
What is Scratch? It is a visual programming environment designed for children and teenagers. Programming here is carried out by moving visual program blocks, small “bricks” are combined into “branches”. Everything is simple: it is enough to get the block from the script menu and transfer it to the field for programming, and we will observe the result on the stage on the right.
In Scratch, blocks are divided into sections: movement commands, sensors, conditions, etc. This material is a programming school for children Pixel will tell you what types of constructions exist in Scratch.
Let’s create an easy and exciting game, and in the process we use Scratch blocks, from which we will start getting to know this environment.
Contents
Creating the first game in Scratch
Our game will consist of catching watermelons. A cat named Scratch, the main character of the environment, will run around the stage and collect pieces. But he will have to be careful and not eat a piece that has already been bitten off.
All Scratch programs start with blocks from the Events panel. Our game (a program for cats) will not be an exception. As we have already mentioned, the palettes are located on the left, they help to competently structure our blocks like
-
The program will be launched by clicking on the flag, for this we will move the “When the flag is clicked” block to the field. Then we use the block from the “Variables” palette. In the “Create variable” window, write the name “Watermelon”. It will count the watermelons caught. We attach the “Set my variable” block with the value 0 to the previous block and change my variable to the newly created Watermelon. This block will set the initial value in our calculation.
-
Then let’s take the block from the “Management” panel called “Repeat always”. It will loop the program inside this block endlessly.
-
From the blue “Movement” palette, get the “Move to random position” block and change the position to “Mouse Pointer”. So we will set the movement of our cat using the mouse.
-
Remove the “If, then” block from the “Management” palette. It will check the condition.
-
If we catch 10 watermelons, we win. We will create this condition using the Operators panel block. We will need an equality block. Let’s enter it into the dark diamond of the “If, then” block. From the “Variables” palette, take out the “Watermelon” block and insert it into the left window of the operator, then change the value from 50 to 10 on the right.
-
From the “Appearance” palette, get the “Say hello for two seconds” block, with its help the cat will be able to announce the victory. Let’s change the text to the appropriate one.
After winning, the game will restart. To do this, let’s reset our “Watermelon” variable using the already familiar “Set Value” block.
Next, from the “Events” panel, we will get the “Send Message” block, with which we can go to the next program for a new sprite.
Adding a new watermelon sprite
We will add the next sprite by clicking on the image icon in the lower right corner. We will get to the sprite library and here we will be presented with a huge variety of models, we need to find a watermelon.
Now we need to get a piece from a whole watermelon, for this we will change his costume. This can be done in the “Costume” tab located in the upper left corner of the screen.
A whole slice of watermelon will also have its own program.
-
It will start with the recognizable block “When the flag is clicked”.
Then we will remove the “Repeat always” block.
-
It will endlessly repeat two blocks from the same “Management” palette. “Wait one second”, where we will change the number one to two, and “Create a clone of yourself”, which will allow you to catch a lot of watermelon slices that constantly appear.
Separately, we will create a program that sets the random movement of watermelon slices through the scene.
-
From the “Management” palette, we will extract the “When I start as a clone” block and attach to it the “Move” – ”Fly one second to a random position” block from the “Movement” palette. Let’s change the number one to two.
-
The next program on this sprite starts again with the “When I start as a clone” block. Then the “Repeat always” block. We will attach the conditional block “If then” to them. Add the condition block from the “Sensors” panel – “applies to the mouse pointer”, change the mouse pointer to sprite 1. This block checks the touch of our watermelon slice and the cat.
If the cat touches the watermelon, the particle will disappear from the screen. To do this, remove the “Hide” block from the “Appearance” panel, and change the value of the “Watermelon” variable to one.
And finally, after switching from the cat program, that is, using the “When I receive a message” block, add a block from the “Management” panel – “Delete clone”.
An additional condition for the game
But the game will not be so simple. Let’s add a bitten piece, when catching which our accumulated points of watermelons will decrease. We will do it similarly to the previous particle, we will only change the drawing of the particle itself using drawing tools.
The programs for the bitten piece will be identical to the programs for the whole, so it is enough to transfer them from one sprite to another.
The only difference will be that when picking up a bad particle, the watermelon variable will not increase, but decrease, so let’s change the value to -1.
That’s it, let’s try to launch and play our game. Click on the green flag and try to catch 10 only the best particles.
That’s how quickly and simply it was possible to create a simple game in Scratch, using various blocks from the palette.
Video: getting to know blocks in Scratch and creating your first game
***
And if you want to learn more about programming in Scratch, come to courses to the online school “Pixel”. We teach children to create games and animations from scratch, introduce them to block programming.