logo

Introduction

This project is inspired by the amusement park game Whack-a-mole where the player strikes moles back down into their holes.

Overview of the project

Hey 😃 In our game we will program the ghosts to disappear when we click them.

The goal is to click remove as many as possible in 30 seconds.

Step 1: Create a Flying Ghost

Checklist

progress

Start a new, empty, project and delete the cat

  • Change the backdrop to screenshot

  • To add a ghost, click screenshot Select the sprite screenshot

  • Give the ghost the name Ghost1

  • You should now create a variable that controls how fast the ghost moves
  • We can use this later to change the speed when the game is over
  • In the Code section choose the Variables category
  • Now click the screenshot button

  • Name the new variable and check For this sprite only screenshot

  • On the stage, you will see the variable is called screenshot

  • Uncheck the box next to the variable so that it does not appear on scene: screenshot

  • We want the ghost to move when the game starts. We can do this by creating the following script:

when green flag clicked
    set [speed v] to [5]
    forever
        move (speed) steps
    end

Test Project

screenshot
  • Does the ghost fly across the screen?

  • Why is the ghost stuck when it hits the edge of the screen?

Checklist

  • To prevent the ghost from getting stuck in the edge, we must make it turn when it hits it
  • We can do this adding the block if on edge bounce
  • The script then looks like this:
when green flag clicked
        set [speed v] to [5]
        forever
            move (speed) steps
            if on edge bounce
        end
  • To stop the ghost from turning upside down, click on the screenshot box above the figure
  • Select the middle rotation mode screenshot

Test the project

screenshot
  • Does the ghost fly back and forth?
  • Does the ghost fly the right way?

Things to try

  • Change the speed variable so that the ghost runs faster or slower

  • How can we make the ghost fly faster the longer it flies?

    Tip

    • This is quite difficult, so do not worry if you do not understand how. You will get more hints along the way.

Step 2: Make the ghost appear and disappear

Checklist

progress

Let's make the ghost appear and disappear!

  • We will now create a new script, which will run at the same time as the script as moving on the ghost

  • The new script shows the ghost for a random amount of time and then hides it again after a random time

    when green flag clicked
      forever
        show
        wait (pick random (3) to (5)) secs
        hide
        wait (pick random (2) to (4)) secs
    end
    

Test the project

screenshot
  • Does the ghost move from side to side?
  • Does it disappear and reappear?

Things to try

  • Try to change the numbers in the code where it says pick random () to ()
  • What happens if you choose very large or small numbers?

    Tip

    • This may give you a new hint as to how we should make the ghost go faster the longer you play

Step 3: Conjure away the ghost with one click!

progress

Make the ghost disappear!

Checklist

  • Go to the Sounds tab, add a new sound screenshot

  • Search for the sound Fairydust in the search field and select it

  • Now create a script that will make the ghost disappear when the player clicks it

    when this sprite clicked
         hide
         start sound [fairydust v]
    

Test the project

screenshot
  • Does the ghost disappear with a magic sound when you click it?

Things to try

  • Record your own sound. You can use this in instead of the fairy dust sound

Step 4: Add time and points

progress

Checklist

Add score and a time limit

  • Create a new variable called score

  • Make sure this one applies For all figures

  • Now add a new block so that the score variable is increased by 1 point each time the player clicks the ghost

    when this sprite clicked
          hide
          start sound [fairydust v]
          change [score v] by (1)
    
  • Next create a new variable called time. This variable can show on the screen

  • Now add a new script that sets the time variable to 30 and the score variable to 0 when the green flag is clicked.

  • Then use a repeat until block to wait for 1 second before reducing the time by 1 second

  • This should run until time runs out

  • When the time runs out, you should stop the game with stop all

When green flag clicked
  set [time v] to [30]
  set [score v] to [0]
  repeat until <(time) = [0]>
      wait (1) seconds
      change [time v] by (-1)
  end
  stop [all v]

Test your project

screenshot

Save your project

progress

Good job! You've made an amazing Whack a Ghost game! Follow the next steps to make it even better!

An extra challenge: More ghosts!

screenshot

One ghost is good, but more is even better! Let's have three ghosts flying around!

  • Make the ghosts be different sizes by choosing a ghost and changing the number in the size

Licence

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Derived from work at https://github.com/kodeklubben/oppgaver/tree/master/src/scratch/spokelsesjakten