Creating Games in Scratch for ICSE Class 6

An Introduction to Creating Games in Scratch 

for ICSE Class 6


Hello friends, I hope you have already read the previous post on An Introduction to Scratch programming for ICSE Class 5. We will not and need not repeat the things that you learnt in the previous lesson. So we will build upon what we already learnt in the previous lesson.

Scratch is a good software to make Animations, Stories, Games, Music and Drawing and so on. We will learn briefly the tools available in Scratch to do all these things. We will also need to stick to the scope of the Syllabus that ICSE board has prescribed for your class, so we can not go overboard. We will stick to just enough information that can be useful in your school exams. I hope things are clear to you by now.

Components of the Scratch Editor 

I will not repeat this section as we have seen it in pretty much detail in the previous lesson. If you like you can read it from this link.

Adding Backdrop on the Stage


The stage is the area in Scratch where we see all the action taking place. If you have seen a stage of a Theater, you can compare this to it. We can add a backdrop to this stage. It is like adding a wallpaper to your desktop or to your smartphone. A backdrop is an image that you can choose from the Scratch library.
 You will see this icon as seen in the image, in the bottom-right corner of your Scratch editor. Click on it and a menu pops up. Clicking on the magnifying glass will take you to the backdrop selection page or the backdrop library. There are several backdrops to choose from. Choose the one suitable to your project and it will appear in the stage area in the Scratch Editor. 










The backdrop library
Selected backdrop appears on stage
You can choose one or more backdrops for your project. You can change them with a code during the course of the program. It means you can pre select all the backdrops that you  want to see in your project. They will all appear inside the Backdrops panel. 


Here is a script that will use multiple backdrops that you have added in your project. It will change the current backdrop with the next one whenever you press the spacebar. 

You need to first select the Stage panel in the bottom right, after that select the backdrop tab. Then add this code in the script area. 

Changing the size of the sprite 

In the previous version, there were icons on the toolbar to enlarge or shrink an image, the sprite. But now it has been deprecated in Scratch. You can specify the size of the sprite in the code itself, in terms of percentage. This is an example of a script that will make the sprite smaller by 10 percent whenever you will press the spacebar. Look at the first block after the Green Flag clicked block. It is where you can set the initial size of your sprite. 


Customize Sprite

If you have added a few sprites in the scratch editor before, you should notice in the Costumes tab more than one images of the same sprite. These images are depicted in different action. An image of a sprite is called a costume. When you display these images one after the other rapidly, they appear as if the sprite is making movement. 

A good thing about these costumes is that you can create a new costume. You can select any of the costume and right click on it, and select duplicate. It will add another of the same image but with a different name. You can now edit this image. 
You can flip the image horizontally or vertically if needed and use it as a new costume.

customizing costumes


If you change the image from Bitmap to vector mode and then ungroup it, you will see different nodes of that image. There are handles to stretch or rotate the nodes, which will help to create an image with a different position. After editing is over, group them and convert the image back to bitmap mode. 

This is how you can customize a sprite.

Customize Backdrop 

We have seen how we can add more than one backdrop from the library and can bring them on the stage using coding. We can also use the paint editor in Scratch. First select the Stage pane in the bottom right, then click on the Backdrops tab on the top right corner of the screen. You will see a blank backdrop. You can change this backdrop to bitmap mode, and fill in colors of your choice. You can also add Text and some shapes available in the paint editor. This way you can create your own customized backdrop. You can even give it a name of  your choice. 




Multiple Sprites on the stage

You can use the Sprite info pane below the Stage area, and click on the "Choose a sprite" icon and add one or more sprites in the stage area. You can add as many sprites on the stage as you can accommodate. But you will have to code them all separately. You need to first select the sprite's thumbnail from the info pane and then add code in the code or script area. 

Remember to use the hat block from the Events category - "When Green Flag Clicked" as your first block in your code.
multiple sprites on the stage



Block Categories


We have already seen the Motion, Looks, Sound and Control block categories in the previous lesson. Today we will learn about the Events category.

It has six Hat blocks, and two stack blocks. Hat blocks are the type of blocks that are placed at the top of the Script. A script begins with a Hat block. "When green flag clicked" is the first block that you will add into your project.

There is another important block called "When space key pressed". If you click on the space words in this block you will see a long menu listing all the keys on your keyboard. You can use this block to add interaction into your scratch project. When you press one of the keys, then add some action to be performed.

The third important block is the "When this sprite clicked". If you add this block to a sprite and add some action in the script, then that code will run when you click that sprite while the scratch project is running. This is very much useful in creating interactive animations, stories and games. 


 Sensing 


Sensing blocks are the light blue colored blocks. They are mostly reporter blocks. It means whenever they are used, they report some information into the script. The hexagonal shape of these blocks fits into the golden colored Control blocks. That is where they are used. You can get/sense  information such as if one sprite is touching another one, if mouse pointer is touching a sprite, if one color is touching another color, if one sprite is closer to another sprite or not, if a certain key is pressed or not, what are the x and Y co-ordinates of a sprite in the stage. 

You can sense all this information and then use this information to create games in Scratch. 

Operators 


Operators are green colored blocks. They can be used to make mathematical calculations as well as comparison of two values. You can even use sensing blocks inside the operators. There are comparison operators, boolean operators as well as text Strings. These are necessary for implementing your game logic. 

Variables



Variables are the Golden colored blocks. They are used to create a counter or for counting number of events as they take place in your scratch project or game. 

There is also another type called a List, just below the Variable blocks. It allows you to create a number of variables as a single list. I haven't yet used it. But I mentioned it so that it does not go unnoticed. 


My Blocks


My blocks are pink colored blocks. It is a custom block creation tool. If you need to use a code routine in your project more than once, then instead of adding so many code blocks, you can create a single block using the My blocks dialog box. This will help you to reduce the number of code blocks appearing in the script area. Very useful when your project starts growing bigger.

Control Blocks

These are the Golden colored blocks, which have all the Loops in it. These are the blocks that include other blocks inside. 
Repeat - This block can be added just below any other stack block, or directly after the Beginner Hat block. The default number is 10. You can change this number to anything you want. You can then add other code blocks inside this block. It will keep on growing as you add more blocks in it. It will repeat the code inside it for the number of times written in the circle.

Forever - You can add any code in this block, and it will keep repeating till you press the Red stop button or Stop all the Script using the Stop block. 

If - Then : Is called a Conditional statement in programming terms. You can add a Blue colored Sensing block between the slot of If - Then. That is the condition, if fulfilled, then the code that you add inside this block will execute. Very useful in Game creation. 

If -Then -Else : You can have two set of blocks that will run. One set will run if the condition is fulfilled, the other set will run if it is not fulfilled. 

There several other control blocks that you will find in the Scratch 3 Editor. 

We will watch how these code blocks function in the video tutorials. 

Tutorial 4


Tutorial 5


Tutorial 6



Tutorial 7


Popular posts from this blog

Programming for kids - course 4 # Artist Functions with parameters

Programming for kids - Course 4 # Artist for loops

Programming for Kids - Course 4 # Bee: Functions with Parameters