Scratch exercise 165b

Repel - intermediate

In this tutorial you will create a game in which a sprite is cloned, and then the clones are repelled (kicked) by the cat sprite.

 

NOTE: You need to use Scratch Desktop (version 3 of Scratch) or higher.

 

Complete these steps ..

 

1. Open Scratch Desktop (v3), OR create a new game by choosing "File>New" from the top menu ..

 

 

2. Under the stage click the Paint new sprite button ..

 

Now, select the rectangle tool, hold down the shift key on your keyboard and drag out a square like this ..

 

We want this sprite to rotate when it is kicked by the cat sprite. We will simulate rotation by using costume changes.

Right-click on the costume thumbnail image and select "duplicate" to make a copy ..

 

Select the duplicate, and then choose the selection tool (arrow). Now click on the square and use its rotate handles to turn it by 45 degrees so you have a diamond shape ..

 

Name the square sprite "square" and then select the Cat sprite and name it "Cat" ..

 

 

 

3. Make a variable named "cat direction" ..

It will appear on the stage, leave it visible for now.

 

NOTE: This variable is going to be used to make the square sprite move in the same direction as the cat sprite when it is touched (kicked or repelled) by the cat sprite.

 

 

4. Select the Cat sprite under the stage and make it's "direction" property visible on the stage ..

 

 

 

5. Add this code to the cat ..

 

Press "B" on your keyboard to test your game.

NOTE: Notice how the "cat direction" variable is forever filled with the cat direction property.

When you are ready press "e" to end your game and then turn off (un-tick) the direction property and cat direction variable displays on the stage.

 

 

6. Use the File menu to save your game. Name it "repel intermediate v1.sb3" ..

 

 

7. Add the following code to the square ..

 

NOTE: Notice how after the clones are created, you must have duplicate code for the original square sprite and it's clones.

 

Press the "B" key on your keyboard to test your game.

When you are ready press the "E" key to end your game and continue working on it.

 

 

8. Use the File menu to save your game.

 

 

9. Well done, you've finished the exercise. Can you turn it into a game?