Introduction to using Scratch


Watch this video to see how easy it is to make many types of projects using Scratch.


The Scratch development environment

windowOverView.gif

















Help

1c.jpg
To find out what any block does, right-click on the block and then click on help.

1c1.jpg

If the block is in the scripts area, you can also duplicate or delete the block.


Sprites

Sprites are the characters in a Scratch program. They can move and change appearance. We write scripts by dragging code blocks into the script area, Scripts are instructions for the sprite and control the movement and appearance of a sprite. When you first start Scratch, there will be one sprite - the cat - ready for you. you can change this sprite or add extra sprites. Each sprite has its own scripts.

The green flag

When you click on the green flag in the top right hand corner of the screen, your Scratch program will start running.

Green_Flag.jpg


Drag the flag block (found in the control group of blocks) into the script area. Now any blocks that you attach below this control block will run when you click the flag.

The control blocks with the curved tops always go at the top of a group of blocks. This group of blocks is called a script. The script runs when the condition specified in the block occurs. In this case, the script will run when the green flag is clicked. You can also write scripts that will run when keyboard is pressed or the mouse is clicked in other places.


Move the Sprite

2move10.jpg
Drag the move block (found in the motion group of blocks) onto to the flag block. Then click the green flag to see the cat move.


Save your project

Click on save as button at the top of the screen to save your project. Remember to regularly save your project by clicking on the save button.

Animate the Sprite

Each sprite can have many costumes. There are two costumes already loaded for the cat. Later you can load new costumes or draw your own. The costumes show the cat's legs in different positions. Changing costume makes it look like the cat is walking.

3.jpg
Drag the next costume block (found in the looks group of blocks) to the bottom of your script. Then click the green flag to see the cat move.



Keep the cat moving

The cat takes one quick step. You can keep the cat moving by adding an instruction to repeat this step.

4.jpg Drag the repeat 10 times block into your script and make sure that the step and next custome blocks
are inside its mouth. Then click the green flag.





5.jpg .

You can keep the cat moving until you click on the red stop sign by using the forever control block




6.jpg

The cat is moving very quickly. You can slow the cat by adding a wait command.
Drag the wait 1 sec block into the control block.
If the cat moves too slowly, you can experiment by changing the 1 sec to shorter times.



When you are experimenting with moving the cat, click on the cat and drag it back to the left of the screen ready to try again.

Position the cat

Add some code so that the cat automatically moves back to the left side of the screen when the green flag is clicked.

Background Explanation: Coordinates: X axis and Y axis
The x axis is the left-right position on the screen. The y axis is the up-down position.
These values are often referred to as the coordinates of a position.
The centre of the screen has values (coordinates) of x=0 and y=0.
Positions to the left of the screen have x values less than 0.
Positions to the right of the screen have x values greater than 0.
Positions in the bottom half of the screen have y values less than 0.
Positions in the top half of the screen have y values greater than 0.


9.jpg
We can change the position of the cat by specifying x and y values

Drag a set x and a set y block to immediately below the green flag block






91a.jpg


To find out the values for x and y, use your mouse to position the arrow where you want the cat and the x and y values will be displayed.











Control the cat

You can use the keyboard to move the cat.

An if block lets you control the cat depending on which key is pressed. Drag an if block into the forever block. You need to specify the condition i.e. which key will cause the action. Drag the key pressed block into the if block. Select the up arrow option.

Now you need to specify what will happen when the up arrow is pressed. We can change the up-down position of the cat by changing its y value. We use a change block and add or subtract a value because we want to position the cat relative to its current position.

8b.jpg
Drag a change y block into the mouth of the if block. The cat will move up when the up arrow key is pressed. You can change how far the cat moves up by changing the value in the change y block.











9a.jpg


Next step is to make the cat move when the down, left or right arrow is pressed.



Background Explanation: Absolute and relative positions
When we positioned the cat at the start of the script we specified an absolute position - we told it exactly where to go by setting x and y values. The cat will always start the game in the same position.

Here we are specifying a relative position - we are changing the x and y values. The position that the cat goes to depends on where it already was.















Make a game

Now that you can control the cat with the arrow keys, you can make a simple game where you move the cat to avoid obstacles.

Add obstacles to the background

There is only one stage but there can be many backgrounds just as a sprite can have many costumes. To edit the background, click on the stage, and then, in the centre panel, choose backgrounds and then click on edit.

92a.jpg
Use the Paint Editor to add some obstacles to the background. I simply added some blue barriers and a red wall to aim for.














Shrink the cat

When you have finished editing the background, you will notice that the cat is too large to fit between the obstacles.

93.jpg Click on the shrink tool and drag it onto the cat. Click until the cat is small enough.

Try moving the cat around the obstacles.

You will need to experiment with changing the sprite size and repainting the background to make the game not too hard or too easy.


Game play

I decided to end the game with a winning message if the cat touches an obstacle and a winning message if the cat reaches the red wall.

Detect if the cat is touching a wall or obstacle

95.jpg

To test if the cat is touching the wall, use a touching color block to test if the cat is touching the wall colour.

Insert an if block and drag a touching color block into it.

To select the colour, click on the square in the touching colour block and move the pen to the wall on the stage.




Make the cat talk

Type the message into a say block.

Because this is the end of the game, add a stop script block to stop the script running.


Enhance your game

Your game is working but there are many more features that you can add to make it more interesting.

Sound

96.jpgScratch already has some sounds loaded and you can record or import more sounds.
You can also play drums or musical notes.

97.jpgI chose to make the cat meow if losing and to play a drum roll if winning.


For more information on writing music in Scratch see
Make your own music







Background music

Add background music to run continuously while you are playing the game.

99.jpg
Go to the sounds tab for the stage.

There is already one sound loaded but click import to import a new sound from the folders that come with Scratch. You can also import from other sources or record your own sounds.









1ba.jpg
Drag a play sound block to the scripts area for the stage.
Also use a green flag block so that the music will start when you start the game.
This will play the piece of music once.

1b1a.jpg
Add a forever block so the music plays continuously.





Change sprite colour

I decided to change the colour of the sprite when the game ends. I could do this by copying and editing the sprite's costumes to make new costumes of different colours and swap to these costumes when the game ends.

98.jpgA simpler method is to use a change colour block.

This code will change the cat to green if it wins and red if it loses.










Keep the sprite moving

The sprite only moves when an arrow key is pressed. We can make the game harder by keeping the sprite moving at all times and use the arrow keys to change direction.

1d.jpg

Change the script so that the sprite is always moving by putting the blocks which move the sprite outside the if blocks which test whether an arrow key has been pressed.

Delete the blocks inside each if block. Add a point in direction block to each if block.

The cat will always move even if no arrow key is pressed. This will make the game harder as you will need to be quick to press an arrow key before the cat hits a barrier. you might need to experiment with the size and speed of the cat so that it is not to difficult. To change the speed of the cat, you can change the number of steps taken each time or the time waited between steps.