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?


1. Download and save the following three background images, then import them as backgrounds onto the stage ..

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.

Delete the default white background.


2. Download, save and then import this sound file onto the stage ..

Tank wheels.wav


3. Add these 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.


4. Download, save and then import the following sprites ..



Tank turret.sprite

Tank shell.sprite

Enemy tank.sprite

Enemy tank turret.sprite

Enemy shell.sprite

Now delete the cat sprite.


5. Use "File>Save as" to save your game. Name it "Tank battle".


6. Read the text on the "Instructions" sprite and then add these simple 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 these scripts ..


9. Re-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 these scripts to the Tank turret sprite ..


11. Download, save and then import this sound file onto the "Tank shell" sprite ..

Tank shell explodes.wav


12. Because our "Tank shell" has multiple exploding costumes, and we want to include a re-load time, it has a slightly more complex script than the usual one we use. Add it next ..


13. Add the 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.


14. Re-save your game.


15. Add these scripts to the "Enemy turret" sprite ..


16. Download, save and then import this sound file onto the "Enemy shell" sprite ..

Enemy shell explodes.wav


17. Add these scripts to the "Enemy shell" sprite ..


18. Re-save your game.


19. Test your game and correct any mistakes in your scripts. Well done, you've completed this tutorial!