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)
Name of author
Resource originally created in
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
Animating the rocks
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
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.
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