Scratch game making tutorial 135

Haunted house

In this tutorial you will create a game in which the player must escape a haunted house. The player must search the house with a torch and click on items to find the exit.

 

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 then select the Backgrounds tab and import the following 5 background images ..

Haunted-house-1.BMP

Haunted-house-2.BMP

Haunted-house-3.BMP

Haunted-house-4.BMP

Green-field.BMP

Note that , except for the last one, each is a different room.

Ensure they are in the correct order (you can drag them if they are not) ..

 

 

3. Add these scripts to the stage to allow you to End your game, and prepare the sprites ready to Begin it ..

 

 

4. The backgrounds will change as you move through the rooms of the house. You will use a variable to switch them.

Create this variable ..

 

 

5. Select the stages Sounds tab and then Import this sound effect ..

Thunder-and-rain.wav

This sound effect will run throughout the game.

 

 

6. Now add these scripts to the stage ..

Notice that when "prepare game" is received the first background is selected and "Which room?" is set to "1".

 

 

7. Use "File>Save as" to save your game. Name it "Haunted house".

 

 

8. Before the game begins you will tell the player how to play. Use the "Choose new sprite from file" button under the stage to import this image ..

How-to-play.gif

Now add these scripts to show and hide it ..

Notice how this sprite will broadcast "begin game" when it is clicked and then fade out using the ghost effect function.

Press "B" to test the How to play sprite.

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

 

 

9. The player will search the house for an escape route using a torch. Import this image as a new sprite ..

Torch.sprite

To help you understand how it will work, have a look at the torch costume.

 

Add the following scripts to prepare the torch for when the game begins, and for when it ends.

Notice how the Torch is set to "go to front" and to then "go back one layer". You need it to be in front of nearly all the game sprites, but behind the three jump scare sprites which we will import later.

 

 

10. Add the scripts to control the movements of the Torch ..

 

Press the "B" key to test your game. You should be able to read the How to play instructions, then begin the game and move the torch around the stage.

However, there is a problem. The torch can move too far, revealing the stage background at its edges. You need to fix this problem by restricting the torch's movements with some "if" scripts.

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

 

Edit the script you just made by adding new "if" scripts, like this ..

 

Press the "B" key to test your game. The Torches movements should now be restricted and the stage background should remain hidden at the edges.

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

 

 

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

 

 

12. We are going to use a single door sprite to move between the rooms. Import this image as a new sprite ..

Door.sprite

We will re-size and re-position this door in each of the four rooms.

Click on the "only face left-right" button ..

 

 

13. Let's add a sound effect to the door. Download and save this sound effect and then click on the Sounds tab and import it ..

door-swoosh.wav

 

 

14. Add these scripts to the door sprite ..

Notice how each time the door is clicked, the "Which room?" variable changes by 1. If you go and look at the stage scripts you will see that this triggers a background change to the next room.

 

 

15. When the room changes (stage background) you need to re-size and re-position the door for the new room. Add these scripts ..

 

Press the "B" key to test your game. You should be able to click on each door and move through the house to escape.

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

 

 

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

 

 

17. Import this Game over sprite ..

Game-over.sprite

 

Let's make it appear at the end of the game. Add these scripts ..

 

 

18. In each room you need to have some items for the player to click on. You'll add two items for each room. You can add your own items later.

Import this sprite for "Haunted-room1" ..

Rocking-horse.sprite

Window.sprite

 

 

19. Select the Rocking horse sprite, switch to the Sounds tab and import this sound effect ..

Creaky-1.wav

 

 

20. Now add these scripts ..

Notice how this sprite will only appear if "Which room?" = 1, so it only appears in the first room.

 

 

21. Add the scripts to make the Rocking horse animate ..

Press "B" to test the rocking horse. If you like you can temporarily turn off (hide) the Torch sprite so you can see things better.

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

 

 

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

 

 

23. Import this sprite for "Haunted-room1" ..

Window.sprite

 

Select the Window sprite, switch to the Sounds tab and import this sound effect ..

Shudder.wav

 

 

24. Now add these scripts ..

Notice how, like the Rocking horse, this sprite will only appear if "Which room?" = 1, so it only appears in the first room.

 

 

25. Now add the scripts to make the Window costume change when it is clicked ..

 

Press "B" to test the window sprite.

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

 

 

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

 

 

27. The first room is complete. Next complete the second room.

Import this sprite for "Haunted-room2" ..

Spider.sprite

 

 

28. Select the Spider sprite, switch to the Sounds tab and import this sound effect ..

Scitter.wav

 

 

29. Now add these scripts ..

Notice how this sprite will only appear if "Which room?" = 2, so it only appears in the second room.

 

 

30. Add the scripts to make the Spider animate ..

 

Press "B" to test the Spider.

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

 

 

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

 

 

32. Import this sprite for "Haunted-room2" ..

TV.sprite

 

Select the TV sprite, switch to the Sounds tab and import this sound effect ..

White-noise.wav

 

 

33. Now add these scripts ..

Notice how, like the Spider, this sprite will only appear if "Which room?" = 2, so it only appears in the second room.

 

 

34. Now add the scripts to make the TV sprite animate when it is clicked ..

 

Notice how you are also adding a jump scare broadcast "jump scare ghost". Now add the Ghost sprite before you test your game.

 

 

35. Import the Ghost sprite which you will use for the first jump scare ..

Ghost.sprite

 

 

36. Switch to the Ghost sprites Sounds tab and import this sound effect ..

Spirits-1.wav

 

 

37. Now add the script to prepare the Ghost sprite ..

 

Next, add the scripts for the jump scare ..

 

Press "B" to test the jump scare by clicking on the TV.

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

 

 

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

 

 

39. You have completed the second room, so next move on to the third.

Import this sprite for "Haunted-room3" ..

Ghost-bride.sprite

 

 

40. Select the Ghost bride sprite, switch to the Sounds tab and import this sound effect ..

Slider.wav

Set the Ghost Bride sprite to "only face left-right".

 

 

41. Now add these scripts to the Ghost bride ..

Notice how this sprite will only appear if "Which room?" = 3, so it only appears in the third room.

 

 

42. Add the scripts to make the Ghost bride animate ..

 

Press "B" to test the Ghost bride.

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

 

 

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

 

 

44. Import this sprite for "Haunted-room3" ..

Box.sprite

 

Select the Box sprite and add these scripts ..

Notice how, like the Ghost bride, this sprite will only appear if "Which room?" = 3, so it only appears in the third room.

 

 

45. Now add the scripts to make the Box sprite change its costume and broadcast the second jump scare when it is clicked ..

 

You'll add the second jump scare "3 ghosts" sprite before you test your game.

 

 

46. Import the "3 ghosts" sprite which you will use for the second jump scare ..

3 ghosts.sprite

 

 

47. Switch to the 3 ghost sprites Sounds tab and import this sound effect ..

Approach.wav

 

 

48. Now add the script to prepare the 3 ghosts sprite ..

 

Next, add the scripts for the jump scare ..

Notice how in this script the 3 ghosts appear to come out of the box.

 

Press "B" to test the jump scare by clicking on the Box.

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

 

 

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

 

 

50. You have completed the third room so next move on to the fourth and last room.

Import this sprite for "Haunted-room4" ..

Mirror.sprite

 

 

51. Select the Mirror sprite, switch to the Sounds tab and import this sound effect ..

Glass-explodes.wav

 

 

52. Now add these scripts to the Mirror ..

Notice how this sprite will only appear if "Which room?" = 4, so it only appears in the fourth room.

 

 

53. Add the scripts to make the Mirror react when it is clicked ..

 

Press "B" to test the Mirror.

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

 

 

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

 

 

55. Import this sprite for "Haunted-room4" ..

Toilet.sprite

 

 

Select the Toilet sprite and add these scripts ..

Notice how, like the Mirror, this sprite will only appear if "Which room?" = 4, so it only appears in the fourth room.

 

 

56. Now add the scripts to make the Toilet sprite broadcast the third jump scare when it is clicked ..

 

Next, you'll add the third jump scare "Hoodie Ghost" sprite before you test your game.

 

 

57. Import the Hoodie ghost sprite which you will use for the third jump scare ..

Hoodie ghost.sprite

 

 

58. Switch to the Hoodies ghost sprites Sounds tab and import this sound effect ..

Sweep-fall.wav

 

 

59. Now add the script to prepare the Hoodie ghost sprite ..

 

Next, add the scripts for the jump scare ..

 

If you have turned off (hide) the Torch, now is a good time to turn the show script back on.

Press "B" to test the complete game, including the third jump scare by clicking on the Toilet.

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

 

 

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

 

 

61. Well done, you've finished this tutorial!

Can you add new items to the rooms?

Can you add new rooms of your own?