Scratch game making tutorial 129

Artillery strike

In this tutorial you will make a game in which the player must destroy as many attacking tanks and bombers as possible before their artillery is destroyed or the time runs out.

 

Complete these steps ..

 

1. Create a new game then delete the cat sprite.

 

 

2. Download this background image and then import it to the stage ..

 

 

3. Create these variables ..

 

Here's what they do ..

Variable Description
Bomber visible? This is used to stop bombs dropping when the bomber is off the stage
Countdown Simple timer
Enemies destroyed Counts bombers and tanks destroyed
Firing angle Used to determine the distance the artillery shell will travel
Lives Artillery lives
Shell speed Can be used to set the artillery shell speed
Tank speed Can be used to set the tank speed
Tank visible? This is used to stop tank shells firing when the tank is off the stage

 

 

4. Place the visible variables on the stage like this ..

 

 

5. Download, save and then add these new sprites ..

 

 

6. Use "File>Save as" to save your game. Name it "Artillery strike".

 

 

7. Select the stage Scripts tab and add these scripts to the stage to begin and end the game ..

*Note how the first broadcast is "prepare game" and NOT "begin game".

 

 

8. Now add the scripts for the "Countdown" and to initialise "Enemies destroyed".

 

 

9. Select the game "instructions" sprite and add these scripts ..

This sprite will show first and then hide when the game begins.

 

 

10. Select the Artillery sprite and add these scripts ..

This sprite does not move. It just provides a base for the barrel to pivot on.

 

 

11. Select the "Barrel" sprite and add its scripts ..

Notice how the barrel angle follows the mouse-pointer but ony between a specified range of mouse x and y positions.

 

12. Press "B" and then click the instructions to test the barrel. Move your mouse-pointer up and down.

 

 

13. Re-save your game.

 

 

14. Select the "Artillery shell" sprite and add it's first script ..

 

 

15. Download and save this sound effect and then select the Artillery shell's Sounds tab to import it ..

gunshot-1.wav

 

 

16. Now carefully add the firing script ..

*Notice how the "Firing angle" (shell distance) increases the longer you hold the mouse button down ("repeat until not mouse down").

 

 

17. Use "File>Save" to re-save your game and then press "B" to test it. You should be able to control the angle of fire and distance travelled with the mouse.

 

 

18. Press "E" to end your game and then select the Tank sprite.

Select it's costume tab.

Click the Edit button of the first costume and note that it is upside down. It has to be this way because we want the tank to move right to left across the stage and also to follow the green path.

Also note that it has three small differently coloured rectangles. We will use these to help keep the tank on the green path.

When you are ready, click "Cancel".

Also .. notice that the tank has several costumes so that it will animate when it is hit with an artillery shell.

 

 

19. Download and save this sound effect, and then select the Tank's Sounds tab to import it ..

big explosion.wav

 

 

20. Add the tank sprite's first script ..

 

 

21. Add the main script to make the Tank move along the green path towards the Artillery sprite ..

*NOTE! You will need to sample the coloured rectangles on the front of the tank, and the green path, to complete the script.


 

 

 

22. Re-save your game and then re-test it. Does the tank appear and move along the path? Can you fire at and hit it (using the mouse)? If not, fix any errors in your scripts before continuing.

 

 

23. Select the Tank shell sprite, then download and save this sound effect, and then select the Artillery shell's Sounds tab to import it ..

bang.wav

 

24. Add the Tank shell scripts ..

 

 

25. Re-save your game and then test it. Does the tank fire at the Artillery as it moves? Does the Tank shell explode when it hits the Artillery? If not, fix any errors in your scripts before continuing.

 

 

26. Select the Bomber sprite and then select it's Sounds tab to import big explosion.wav again. Note how the bomber has several costumes.

 

 

27. Now add the Bomber scripts ..

 

 

28. Now select the bomb spite and add its scripts ..

 

 

29. Re-save your game and then test it. Can you shoot down the bomber? If not, fix any errors in your scripts before continuing.

 

 

30. Select the Bomb sprite and then select it's Sounds tab to import bang.wav again.

 

 

31. Re-save your game and then test it. Is the bomber dropping bombs on the Artillery? If not, fix any errors in your scripts before continuing.

 

 

32. Select the Game Over sprite and add these scripts ..

 

 

33. Re-save your game. Well done. You have finished this tutorial. Can you add things to make the game better?