Scratch exercise 134b

Force field - advanced

In this exercise you will add a force field to the Cat to protect it from damage caused by enemies.

 

Complete these steps ..

 

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

 

 

2. Select the stage by clicking on the Stage thumbnail under the stage.

Add these scripts to the stage ..

 

 

3. Select the Cat sprite and then do the following ..

 

 

4. Click the cat sprite thumbnail under the stage to select the Cat (sprite1) ..

 

 

5. Create an "enemy" sprite which can move about the stage and which the Cat sprite must avoid.

Something like this ..

 

When you are done, test your game. Press the "b" key on your keyboard to begin your game, and then move the mouse-pointer around the stage. Press "e" for end when you are ready to continue making your game.

 

 

6. Use "File>Save as" to save your game. Call it "Force field advanced"..

 

 

7. Create a force field for the Cat. Click the Paint new sprite button under the stage, choose a new colour, and use the largest brush size again to paint a force field image like this ..

 

 

8. We will make the force field stick to the Cat but only appear when we activate it.

Start by adding this script ..

 

 

9. Let's add a script which turns the force field on for 6 seconds after which it turns off and cannot be re-activated for 10 seconds.

We'll also add a display which countdowns the seconds with a display on the stage.

Create these variables ..

The "is force field on?" variable does not need to be seen on the stage so you can un-tick it.

 

 

10. Add these scripts to the force field ..

 

 

11. Press the "B" key to test your game. The countdown should work for the 6 seconds of force field activation and the 10 seconds when you cannot re-activate it.

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

 

 

12. Use "File>Save" to re-save your game.

 

 

13. Let's add an alternative script that let's you toggle the force field on and off. We will use a keyboard key press to do this. The first time it is pressed the force field will turn on. The second time it is pressed the force field will turn off.

 

Add these scripts to the force field ..

 

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

 

 

14. Finally we need to add a script to the enemy to make it bounce off the force field. Add this script ..

Press "B" to test your game. Make sure the enemy bounces off the force field.

 

 

15. Use "File>Save" to re-save your game.

You've finished this tutorial. Well done! Now, try to make a complete game from this exercise.