Note:

The ‘Balloons’ project has been moved to the Additional Scratch Projects section.

Introduction

You are going to make a ghost-catching game!

Step 1: Animating a ghost

Activity Checklist

  • Start a new Scratch project, and delete the cat sprite so that your project is empty. You can find the online Scratch editor at jumpto.cc/scratch-new.

  • Add in a new ghost sprite, and a suitable stage backdrop.

    screenshot

  • Add this code to your ghost, so that it repeatedly appears and disappears:

        when flag clicked
    forever
        hide
        wait (1) secs
        show
        wait (1) secs
    end

  • Test out your ghost’s code, by clicking the green flag.

Save your project

Step 2: Random ghosts

Your ghost is really easy to catch, because it doesn’t move!

Activity Checklist

  • Instead of staying in the same position, you can let Scratch choose random x and y coordinates instead. Add a go to block to your ghost’s code, so that it looks like this:

        when flag clicked
    forever
        hide
        wait (1) secs
        go to x:(pick random (-150) to (150)) y:(pick random (-150) to (150))
        show
        wait (1) secs
    end

  • Test our your ghost again, and you should notice that it appears in a different place each time.

Save your project

Challenge: More randomness

Can you make your ghost wait a random amount of time before appearing? Can you use the set size block to make your ghost a random size each time it appears?

Save your project

Step 3: Catching ghosts

Lets allow the player to catch ghosts!

Activity Checklist

  • To allow the player to catch a ghost, add this code:

        when this sprite clicked
    hide

  • Test out your project. Can you catch ghosts as they appear? If you find it difficult to catch the ghosts, you can play the game in fullscreen mode by clicking this button:

    screenshot

Challenge: Adding a sound

Can you make a sound each time a ghost is caught?

Save your project

Step 4: Adding a score

Let’s make things more interesting by keeping score.

Activity Checklist

  • To keep the player’s score, you need a place to put it. A variable is a place to store data that can change, like a score.

    To create a new variable, click on the ‘Scripts’ tab, select Data and then click ‘Make a Variable’.

    screenshot

    Type ‘score’ as the name of the variable, make sure that it is available for all sprites, and click ‘OK’ to create it. You’ll then see lots of code blocks that can be used with your score variable.

    screenshot

    You’ll also see the score in the top-left of the stage.

    screenshot

  • When a new game is started (by clicking the flag), you should set the player’s score to 0:

    when flag clicked
set [score v] to [0]

  • Whenever a ghost is caught, you need to add 1 to the player’s score:

    screenshot

  • Run your program again and catch some ghosts. Does your score change?

Save your project

Step 5: Adding a timer

You can make your game more interesting, by only giving your player 10 seconds to catch as many ghosts as possible.

Activity Checklist

  • You can use another variable to store the remaining time left. Click on the stage, and create a new variable called ‘time’:

    screenshot

  • This is how the timer should work:

    • The timer should start at 10 seconds;
    • The timer should count down every second;
    • The game should stop when the timer gets to 0.

    Here’s the code to do this, which you can add to your stage:

        when flag clicked
    set [time v] to [10]
    repeat until <(time) = [0]>
        wait (1) secs
        change [time v] by (-1)
    end
    stop [all v]

    This is how you add the repeat untiltime= 0 code:

    screenshot

  • Drag your ‘time’ variable display to the right side of the stage. You can also right-click on the variable display and choose ‘large readout’ to change how the time is displayed.

    screenshot

  • Ask a friend to test your game. How many points can they score? If your game is too easy, you can:

    • Give the player less time;
    • Make the ghosts appear less often;
    • Make the ghosts smaller.

    Test your game a few times until you’re happy that it’s the right level of difficulty.

Save your project

Challenge: More objects

Can you add in other objects to your game?

screenshot

You’ll need to think about the objects you’re adding. Think about:

  • How big is it?
  • Will it appear more or less often than the ghosts?
  • What will it look/sound like when it has been caught?
  • How many points will you score (or lose) for catching it?

If you need help adding another object, you can reuse the steps above!

Save your project