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!

Target group
School drop outs, Students (primary school), Students (secondary school)
Age group
Children, Teenagers
Proficiency level i
Level 2
Format
Activity sheet
Copyright i
Creative Commons (BY-SA)
Language
English, French , Français

General Objective

Skillset building

Preparation time for facilitator

less than 1 hour

Competence area

3 - Digital content creation

Time needed to complete activity (for learner)

0 - 1 hour

Name of author

Kamithou Mouhidine

Resource originally created in

French
Workshop directions

Introduction

We will create a game centring on the piloting of a helicopter to avoid obstacles. The player will need to collect fuel or the helicopter will crash. Each time on obstacle is touched, the player loses a life, represented by a heart. If three lives are lost, the game is over.

Creating a backdrop and adding sprites

Delete the Scratch cat (the default sprite) — we won’t be needing it for this.   1. Add a backdrop. For example, ‘Stars’ from the category ‘Space’.
2. Add a helicopter and another sprite, for example a wizard’s hat can represent fuel. In this example we have taken Helicopter sprite from pixabay.com and uploaded it to Scratch, while the Wizard Hat is directly from the Scratch library.
3. We now need to create the obstacles, in this case the rocks. Two will come from above and two from below. Give them the same costume.
Rename them Rock 1, Rock 2, etc. 4. We will also create a ‘heart’ to represent the helicopter’s lives. Here we have used ‘Heart’ from the Scratch library.
5. Adjust the sizes of the rocks so that the helicopter can pass between them.

Animating the rocks

1. The following script mean that a rock will appear every 1 to 3 seconds. It will disappear once it reaches the edge of the scree. Add the following blocks to Rock 1:
When the green flag is clicked, the rock disappears, waits between 1 and 3 seconds, reappears (‘show’) at the right of the screen (x= 300). It then advances towards the left of the screen until it reaches the left edge (y= -250). Once the left side is reached, the loop repeats indefinitely.   2. Duplicate the script for the three other rocks. Place the rocks correctly on the screen (two below and two on top). Test the script by clicking the green flag. Make sure the rocks scroll at random times from right to left.

Piloting the helicopter

Here we will create several scripts. Four to direct the helicopter and one to lose fuel every 0.1 seconds (to quantify the gas realistically).   1. Create the following scripts to move the helicopter with the directional arrow keys:

When the up key is pressed, the sprite points up and moves.

 

2. We will now make it so that the helicopter loses altitude and fuel as the game progresses. Write the following script:

When the green flag is clicked, the helicopter goes to the centre of the screen, the variable ‘Fuel’, begins on the value ‘100’ then decreases by 0.1 seconds. At the same time, the helicopter loses 1 on the vertical axis until the variable ‘Fuel’ is equal to 0. When it is equal to 0, the program stops.

Life count system

We now need to implement a life count system. 1. In the stage’s script (click on the stage area in bottom right of the screen), create a variable ‘life’, applied to all sprites, and copy the following:
2. Next, we need code to hide the hearts as they are lost. Copy the following to the heart’s script:
When the green flag is clicked, the heart appeared in the front layer of the stage, meaning that it won’t be hidden behind any other elements, then will appear. The program then constantly checks if the variable ‘Lives’ is less than 3. If it is, the heart disappears.
3. Now we need to duplicate the heart twice. For the second, change ‘If Lives < 3’ to ‘If Lives <2’, and for the last heart: ‘If Lives < 1’.
4. When the helicopter touches the rock, the number of lives needs to go down. Modify the helicopter’s code as follows:

If the colour of the rock (brown here) is touched by the helicopter, one life is lost, and another life cannot be lost before one second passes.

After a hit, one second elapses so that the helicopter has to time to move away.
5. Finally, the variable ‘life’ needs to lose value. Each time the helicopter touches a rock, the number needs to decrease by 1. Add the following blocks to the helicopter’s script so the game stops when ‘Lives’ reaches 0:

When the green flag is clicked, the program will constantly check is the variable ‘Lives’ is less than 0. If it is, the program waits 0.1 seconds (time to allow the last heart to disappear).

Gaining fuel

1. If you have tested the game, you will have noticed that even without touching the rocks, you cannot go very far as the helicopter consumes gas. We will need to implement the ability to recover fuel. Regarding the sprite you have selected to represent fuel (Wizard Hat for example), it will increase the Fuel variable when touched. Copy this to the Hat’s script:

 

 

When the green flag is clicked, the hat disappears, goes to the right of the screen (x= 300), then waits 4 to 8 seconds then appears before appearing. Once visible, it moves towards the left of the screen and disappears when it touches the left side (x= -250). If during this time it touches the helicopter, it (the Hat) disappears and the variable ‘Fuel’ increases by 5.

Bonus

You can improve the game by doing the following:

  • changing the helicopter’s speed or adding more rocks
  • making the fuel move around the screen or appear at random positions
  • adding magical objects that increase your life count. What would you do to add a heart? (Hint: use clones, i.e. automatically recreating the same object to execute a specific script for this sprite)
  • adding a scoring system, for example one that increases as time elapses