>

Scratch game making tutorial 109

Tank battle

This game involves controlling a tank that is under fire from an attacking enemy tank. Can you destroy it before it destroys you?

 

NOTE: You can use any version of Scratch.

 

Complete these steps ..

 

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

 

 

2. Download, save and then open this game file ..

 

 

3. Select the stage and then the background tab.

There are 3 backgrounds. Notice how the last background "water hazard background" has some pools of water drawn on it. When your tank rolls onto them it will slow down for a while.

 

 

4. Add this code/scripts to the stage ..

Notice how we have a 1 second wait before the "stop all" script block. This is to ensure that other housekeeping scripts have time to run first when "E" is pressed.

Also note that we begin the game by displaying the 'how to play' instructions (broadcast "show instructions"), after which "begin game" is broadcast.

 

 

5. Use the File menu to save your game. Name it "Tank battle v1" ..

 

 

6. Read the text on the "Instructions" sprite and then add these simple code/scripts to it ..

 

 

7. Time to create some variables. Create the following and then arrange the visible ones on the stage (see the image at the top of this tutorial) ..

 

 

8. Select the Tank sprite and add this code/scripts ..

 

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.

 

 

9. Use the File menu to save your game.

 

 

10. The tank turret rotation is independent of the tank itself and is controlled with the mouse pointer. This allows the player to move the tank in one direction whilst firing in another. Add this code/scripts to the Tank turret sprite ..

 

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. Because our "Tank shell" has multiple exploding costumes, and we want to include a re-load time, it has a slightly more complex code/scripts than the usual one we use. Add it next ..

 

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.

 

 

12. Add the code/scripts to the "Enemy tank" sprite ..

Note how this sprite has some simple AI that makes it move on its own towards the players Tank, always attacking.

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.

 

 

13. Use the File menu to save your game.

 

 

14. Add this code/scripts to the "Enemy turret" sprite ..

 

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. Add this code/scripts to the "Enemy shell" sprite ..

 

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.

 

 

16. Use the File menu to save your game.

 

 

17. Well done, you've completed this tutorial!