Scratch game making tutorial 89

Minesweeper

In this tutorial you will make a game in which a minesweeper ship must destroy as many mines as possible before it is sunk.

 

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 create the following variable ("for all sprites") and hide all but "ship health" and "mines destroyed" (un-tick) ..

 

 

4. Now add this code/scripts to the stage ..

 

 

5. Save your game using File>Save as. Call it "Minesweeper v1" ..

 

 

6. Add this code/scripts to the "Instructions" sprite ..

 

 

7. Add this code/scripts to the ship ..

NOTE: You will need to complete the touching script block when you have scripted and duplicated "Mine 1".

 

Press the "B" key on your keyboard to test your game.

Press the "E" key to end your game and continue working on it.

 

NOTE: Notice how the ship points and moves towards the mouse to allow the player to control it, and also that the variable "ship direction" always holds the direction that the ship is pointing.

 

 

8. Use the File menu to save your game.

 

 

9. We want the gun Turret to rotate relative to the ships position. Add this code/scripts to it ..

Notice how the we have used the right and left arrow keys to rotate the turret, and a variable named "turret direction" to record the direction value/angle. The "point in direction" script block combines the "ship direction" value with the "turret direction" value to set the rotational angle of the turret, thereby ensuring it always retains its rotational position relative to the ship.

 

 

10. Now add the standard firing scripts for the Shell using the same point in direction block that the turret uses ..

 

Press the "B" key on your keyboard to test your game.

Press the "E" key to end your game and continue working on it.

 

 

11. Use the File menu to save your game.

 

 

12. Finally, add this code/scripts to "Mine 1" ..

 

Press the "B" key on your keyboard to test your game. Use the mouse to direct your ship and avoid the mines, the left and right arrow keys to point your turret and the space-bar to fire at the mines.

Press the "E" key to end your game and continue working on it.

 

Notice how "mine speed" increases by 0.2 steps whenever it re-spawns.

 

 

13. Duplicate "Mine 1" and name it "Mine 2". Go back and complete the touching script block on the Ship.

Press "B" on your keyboard and then the arrow keys to test your game.

Press the "E" key to end it when you are ready to continue working on your game.

 

14. Use the File menu to save your game.

 

 

15. You're done! Can you improve the game? How about adding more mines?