Monday

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


Saturday

Introduction to Scratch Programming for ICSE Class 5

ICSE Class 5 Computer Studies

This lesson will give students a brief introduction to Scratch programming. I am using Scratch3 Desktop software on Windows computer. The lesson is created according to ICSE syllabus for Class 5th.

Introduction to Scratch Software

Scratch is a block based visual programming language. Blocks are the puzzle piece shapes that are used to code in Scratch. The current version of this software is Scratch 3. Scratch has an online editor on their website, which can be run directly in the browser or you can download and install the editor on your computer and run it from there.

Open the Scratch

If you have installed Scratch on your computer, you will see an icon of Scratch on the Desktop. Double click on it to start the Scratch Editor.





As you can see in the above image. The Scratch Screen is divided into several sections. The leftmost area is called “Block Palette”. It contains color-coded block categories. When you click on one of these colored dots, the blocks in that category appear in the right column.
The middle portion is where all your code will reside. This is the area for creating scripts for you.
The upper-right area is called the stage area. It will house all the sprites in your project, And this is where all the action of your project can be previewed. Below the stage there is sprite-info pane. You will see smaller images of the sprites that you add in the stage area.

Components of the Scratch 3 Editor

Stage and Sprite


The rectangular area at the right side of the Scratch Editor is called the Stage. This is where all your sprites ( cartoon images) appear. There is always a cat present when you open your Scratch. The cat is a sprite. And it will appear in the area that is called the Stage.


Sprite info pane

This is the area below the stage. This is where you will find smaller images of the sprites you have added in the stage area.

Blocks

Blocks are the puzzle piece shapes that are used to create code in Scratch. The blocks connect to each other vertically like a Jigsaw puzzle.
There are different shapes of these blocks. They are called Hat blocks, stack blocks, reporter blocks, Cap blocks etc

The blocks are arranged in color-coded categories that appear at the left most column in form of colored dots. When you click on one of these categories, the block in that category are displayed in the next column. We will learn some of the categories like Motion, Looks, Control and Sound in this lesson.










The Green Flag and the Stop signs

Above the stage area there are two distinct symbols. One is a Green Flag and other is a Red colored stop sign. The Green flag is used to start your Scratch script, and preview it in the stage area. And the Red stop sign is used to stop the script. You will need to use these two buttons often to run and to stop your scratch code.



The Script Area


The middle portion of the Scratch 3 editor is used as the script area. You can drag the code from the “Code palette” into this area and create scripts. You can also drag a code block from this area to the left pane so that you can remove or delete that code block.






Adding a sprite


You can add new (images) sprites in your project. When you take the mouse pointer on the cat-head icon in the sprite-info pane, you will see a menu pop up. If you click on the magnifying glass icon, it will open a new page in the Scratch library of images, where you will be able to choose any image you like.



The brush icon called paint open an image editor, where you can draw an image to add it in your project.

The topmost icon is for uploading any image that is available on your computer. You can use any image from your computer to be used as a sprite in your project.













Changing a backdrop


In the right of sprite info pane, there is a stage-pane. You will see an image icon there. If you take the mouse pointer on it, a menu pops up with a message “Choose a backdrop”. If you click on the magnifying glass icon, it opens the backdrop library. You can choose any background image here for your project.










Add Extension


If you click on the icon in the bottom-left corner of the Scratch Editor, (It is called Add-extension) It will open a new page that shows several extensions like Music, Pen, Text-to-speech etc. If you choose any of them, it will create a new Category in the blocks-palette. And you will see many new blocks in that category. We will study the music extension and the pen extension in this lesson.

Saving a project


When you have done some work in your new scratch project, you can save it.
To do that Click on File menu in the Toolbar and choose “Save to your computer”
It will show the folder on your computer. You need to select here the right folder where you want to save your scratch project. You should remember the folder name, otherwise you will find it difficult to find your scratch project on your computer. You need to give a name to your project. Once it is saved, it will have an extension .sb3 , That is the file extension of the Scratch 3 editor. If you need to save your file again after some time you can select the previous file name again and overwrite it, or you can give a new name such as myproject-v1, myproject-v2 etc. Scratch offline editor does not save your file automatically. You need to save it yourself each time.
Opening an existing project

If you want to open your project at some other time, you need to click on File – Load from your computer, and then open the folder where your scratch projects are saved, and then select the sb3 file, that will open the scratch project in the scratch editor.

Closing a project

You can close the editor by clicking on the x sign at the top right corner of the editor. That will show you this dialog box. If you have not saved your project then you can
select to Stay, then save the project. If you have already saved your project then select to Leave. That will close the Scratch Editor.



Block Categories in Scratch

Motion Blocks


Motion blocks is one of the categories of blocks in Scratch. They are color coded medium blue and are used to control sprite movement.

The blocks that can be arranged one below the other are known as Stack blocks. There are 15 such blocks in the Motion category.


The blocks that give certain information into the script are called “Reporter blocks”. There are 3 reporter blocks in the Motion category.



Looks Blocks



The Looks category blocks are color-coded Purple. These blocks are used to control a sprite’s appearance.

There are 17 Stack blocks and three Reporter blocks in this category.















Sound Blocks


Sound bocks are color-coded Pink/Magenta. These blocks are used to control/add sound and MIDI functions.



























Music Blocks

 
These blocks are added as an extension. They are color-coded Green. They can be used to generate musical notes of different instruments in your Scratch project. It is a music making tool. You need to have a teacher who understands musical composition to make god use of this extension. You will have fun in using this extension which can create music through programming.
If you click on the instrument name, you will see a list of dozens of musical instruments to choose from, and you can select the node and beat value for that instrument to play.














Control Blocks

Control blocks are color-coded in Golden color. These are used to control the script.




There are 1 Hat block, 5 C type blocks, 3 Stack blocks and 2 Cap blocks. Cap blocks are the ones that are at the bottom of the script. C type blocks are those, which can include other blocks inside them. They are also called Loops. Hat block is the one that is at the top of a script.







Commonly used blocks in Scratch


Move, Turn, Say, Think, Change-color effect, Play-sound, Play-drum, Wait, Forever.



Move block – This block is found in the Motion category. It will move the sprite a number of steps in the current direction. The value is 10 when you add this block. You can type in any number in the box. You can make the sprite move in the opposite direction if you type a negative number.

Turn – This block is found in the Motion category. There are two types of turn blocks, Clockwise and Anti-clockwise. When you add these blocks, there is 15 written in it. It will turn the sprite 15 degrees. You can type any number in it (0 to 360).

Say – This block This block is found in the Looks category. It will add text in a speech bubble. When you add this block, there is “Hello” written in there. You can type anything you like in the box.

Think – This block This block is also found in the Looks category. It is similar to the Say block, except, it is not addressed to anyone. You can use this block, if you want to show that your sprite character is thinking something. It is useful if you are creating a story using scratch.

Change Effect by - 

This block This block is also found in the Looks category.
You will find a list of 7 different effect to choose from. The already written value ids 25.
You can type a different number ( from 0 to 100 or -100)
You can change the color, brightness and visibility of the sprite. You can also make some visual effects such as fisheye, whirl, pixelate and mosaic.














Play sound - 



This block is found in the Sound category. When you add any sprite, and then add this block, you will see one or two sounds that are suitable for the sprite. You can additionally add more sounds if you want by clicking on the Sounds tab at the top left corner of the screen. Or you can even record your own voice if you want.

Play Drum -






You will find this block in the newly created Music category if you have added the music extension in your Scratch Editor.
The play drum block has a list of 18 different instruments to choose from. And you can specify the beats.











Wait - This is a golden colored Control block. You can use this block to make things wait for as long as you want. There is 1 seconds written when you add this block. You can add a bigger number to make it wait longer. This is a Stack type block. Yo u can add other blocks above and below this one.



Forever - This is also a control block. It is called a C type block because it looks like a C. It is also called a Loop. We can add other blocks above, and below this block, but also we can add other blocks inside this block. Whatever we add inside this block, will run on and on till we do not stop it with Stop block , or by pressing the Red stop button.


Let us see some action in the video tutorials below. 

Tutorial 1


Tutorial 2


Tutorial 3


Featured Post

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 Int...