Scratch game making tutorial 171

Force field defense

In this tutorial you will make a game in which the Cat must survive attacks by skeletons and collect crystals/health. The Cat can use a force field to repel the skeletons, but he can only collect crystals when the force field is off!

 

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. Download, save and then open this game file ..

 

 

3. With the stage selected, switch to the Code tab and add the following code ..

 

Next, create the following variables ..

 

.. and arrange them on the stage like this ..

 

 

4. Create a timer code on the stage so the player can see how long they survived ..

 

 

5. Select the Cat sprite and add its properties and movements code ..

 

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.

 

 

6. When the force field is on, the skeletons and crystals will be repelled. It is best if they will move away in the same direction that the Cat is moving. They need to know this direction. We can do this with the variable "Cat direction".

Add this code ..

 

 

7. Add the code to the Cat to allow it to gain and lose lives ..

 

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. Name it "Force field defence v1.sb3" ..

 

 

9. Select the Force field sprite and add its properties and movements code. Notice how it will follow the mouse-pointer exactly like the Cat does ..

 

Press the "B" key on your keyboard to test your game. You may need to show it first.

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

 

 

10. You can choose 2 methods to activate the force field ..

 

Method 1:

Add this code to toggle the force field on and off with the space bar ..

 

Method 2:

Add this code to make the force field activate for 6 seconds when you press the space-bar, after which it will hide for 10 seconds and you will not be able to re-activate it until the 10 seconds has passed ..

 

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.

 

 

11. Use the File menu to save your game.

 

 

12. Select the skeleton sprite and then add the code to set it's properties and clone it 5 times ..

 

 

13. The skeleton will make a sound when it catches the Cat. Add the code ..

 

 

14. The skeletons will chase the Cat but be repelled if they touch each other, or the force field.

You don't want them to bounce off the edge of the stage, so you will add code to make them re-appear on the other side of the stage when they reach the edge ..

 

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.

 

 

15. Use the File menu to save your game.

 

 

16. Select the Crystal sprite. This sprite will disappear when it is collected by the Cat, but also be repelled if it touches the force field.

Add this code to set it's properties and clone it 40 times ..

 

 

17. The crystals will make a sound, and then delete, when the Cat collects them.

Add this code ..

 

 

18. The crystals will also animate before disappearing when the Cat collects them.

Add this code ..

 

 

19. The crystals remain still until they are touched by the force field or Cat. When the Cat touches them they will be collected, but when the force field touches them they will be repelled.

Add this code ..

 

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.

 

 

21. Use the File menu to save your game.

 

 

22. Finally, add the code to show the Game over sprite and end the game when the Cat has run out of lives ..

 

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.

 

 

23. Well done, you've completed this game tutorial. Can you improve it with your own ideas?

 

Scratch cat and code blocks video screenshot Scratch coding online video courses

Our Scratch coding online video courses are an ideal way for your child to experience our lessons at home, if attending a course or club is inconvenient for you, or if you are waiting to attend a taster session, or an activity.
£24.99 or less