To program this game, we will use the Scratch platform which has the advantage of using visual code: no need to learn a programming language to build your own games and videos!
General Objective
Preparation time for facilitator
Competence area
Time needed to complete activity (for learner)
Resource originally created in
Creating a backdrop
We will first create the playing field. Go to ‘Stage’ in the bottom right corner of the screen and choose a theme (for example ‘woods’ in ‘nature’).
Programming a mischievous ghost
Making the ghost appear and disappear randomly
To make the game more interesting, we can make the ghost appear and disappear randomly. We need to write more code that will be executed alongside the other one. This second code, also in the ghost’s script, will hide the ghost for a random duration, then will make it appear again for a random amount of time. This pattern will repeat until the end of the game.
Write the following code:
Test the code by clicking on the green flag: the ghost should move over and back while disappearing and appearing at random intervals.
Making the ghost disappear when clicked on
For our program to become a game, we need to give the player something to do. Here, they will need to click on the ghosts to make them disappear. When the player clicks on a ghost, its disappearance should be accompanied by a sound effect. 1. First choose a sound effect. In the ‘Sounds’ tab, add a new effect by clicking on ‘Record’. Record whatever sound you like.
2. Write the following code in the ghost’s script:
Adding a timer and a point counter
We have almost everything we need to bring the game to life. All we are missing are the timer and point counter! The player will win points every time they click on the ghost. There will be limited time to win a maximum number of points. We will use variables to keep track of the points and the time. First create a variable ‘score’. Go back to ‘variables’, then ‘create a new variable’. Like the first tick the box ‘For all sprites’. Name it ‘Score’. Change the previous code to increase to score by one point each time the player clicks on a ghost.
Create another variable, again applied to all sprites, called ‘Timer’. Write a code that will set the timer to 30 seconds and put to score to 0 as soon as the player clicks the green flag. We will use the instruction ‘repeat until’ to wait a second and then reduce the timer by one. This operation should repeat itself until the timer reaches 0.
Bonus
We can make the game more interesting by adding more ghosts. Here’s how to do it:
- Copy the ghost by right-clicking on the ghost in the sprites window.
- You can then make the game more complex:
- You could change the sizes of the ghosts;
- change their speed;
- move them around the stage so they don’t all move at on the same axis.
- For the more daring: why not spice up the game? Try to create ghosts of different speeds. The quicker the ghost the more points they carry (for this you will need to make additional speed variables and set them so they each affect different ghosts).