1, 2, 3, code ! - Cycle 3 activities - Step 2.8. Adding challenges


Students finalize their video game by adding additional challenges: a time limit, a tornado that goes faster and faster and moves around randomly, etc. The concepts seen during the previous lessons – tests, loops, variables and events – are all reviewed.

Key ideas
(see Conceptual scenario)


  • The machines all around us simply follow orders (instructions).
  • By combining basic instructions, we can make them execute complex tasks.


  • An algorithm is a method used to resolve a problem.
  • A loop allows the same action to be repeated multiple times.
  • Certain loops, known as “infinite loops,” never stop.
  • Certain loops, known as “iterative loops,” are repeated a predefined number of times.


  • Scratch is a graphical programming environment that uses a simple language.
  • A program is the expression of an algorithm in a programming language.
  • Certain instructions are only executed when an event is triggered. This is known as event-driven programming.
  • Certain instructions are executed one after the other. This is known as sequential programming.
  • The execution of a program is reproducible (if neither the instructions nor the data to manipulate change, the program always gives the same result).


For each student pair

  • A computer with Scratch and the program saved from the previous lesson


Starting the atcivity

The students will likely have noticed that their game can be played but that it is not very interesting because there are no major difficulties. If you pay attention to the obstacles, the game can go on forever.

The class thinks together about a way to end the game and make it harder. There are several options:

  • Option 1: Add a time limit. When the time is up, the game stops. The player's score is based on the number of lives they still have and the number of resources gathered.
  • Option 2: Add a new element to make the game increasingly difficult and eventually end the game. For example, you can introduce a new trap (a tornado, similar to the weather problems in Lesson 3 and Lesson 4, on binary coding). The tornado moves faster and faster and its direction is unpredictable. Eventually, it becomes too fast for the player to avoid and the game will end.

Teaching notes:

  • It is quite possible that the students will think of other ways to end the game. We suggest the teacher to encourage a class discussion to choose one or more options for the students to use (groups can choose the same option if they like).
  • The teacher makes sure that students have an idea before getting started. If one option is appealing but unrealistic, it's best to choose another that is more feasible.

Below, we describe the two options above, as well as several others that do not necessarily make the game more difficult but do make the game more visually appealing or avoid certain bugs.

The tasks below are of varying difficulty, and can be used independently of each other.

We suggest doing at least Activity 2 or 3 to make the game more interesting.


 Activity 1: Make a countdown appear when the game starts (15 minutes)

You can decide that the game only starts after a countdown: 5, 4, 3, 2, 1, go! This can be done very easily, like this:



Or in a more sophisticated way by using a new variable and a loop:



Depending on students' levels, you can have them use the "easy" method or ask them to use a variable and a loop. For the more complicated version, you can also give them all of the elements but out of order and not linked and ask them to put everything in order for the program to get the same result as the first option.


 Activity 2: Limiting the game duration (15 minutes)

Teaching  notes:

  • This task is similar to the first, described above, but you must use the more complicated variation (variable and loop) because it is not feasible to write out a countdown by hand, second by second, that will last several minutes.
  • If the students have already created a countdown (Activity 1), this task will be easy for them. If not, they will need a little more time and may need some guidance.
  • This task reviews the ideas of variables, tests, loops and logical operators.

Limiting the game time is an easy way to make it more interesting. A "time limit" variable must be created, given an initial value and decreased as time goes on by introducing a timeout period to control the speed of the process.

The program stops ("game over" message) when the time limit reaches 0 or when the number of lives reaches 0.

The rover program must be modified to include:


In this example, set the "countdown" to 20 and remove 1 every second.

These values can be changed for a shorter or longer time limit.


 Activity 3: Add a tornado that moves around randomly (15 minutes)

Students already know how to create a sprite from an image and initialize its position. They can, for example, have a tornado start from the lower left corner (X = -230 and Y = -170).

They must then figure out how to make it move around randomly. For the movement to be instantaneous, change the X and Y values. However, it is better to see the tornado move around. The command to do this is "Glide … secs  to x=… and y=…" from the "Motion" block category.

For the tornado to move to any position on the map, simply write the following instruction:

By clicking several times on this instruction, the students can confirm that the tornado moves randomly each time. The movement is always one second, so if the point of arrival is close, it moves very slowly, and if it is farther away, it moves faster.

Now, this instruction needs to be connected to the rest of the tornado program (we have changed the time to "2 seconds" to slow the tornado down).

You must remember that if the rover touches the tornado, the game is over. The following instruction is added to the tornado program:


 Activity 4: Make the tornado bigger (15 minutes)

To make the game even harder, you can make the tornado get bigger as resources are gathered. At this point in the project, this task should not be too difficult.

  • In the resource programs (ice and plants), send a message each time a resource is gathered.

  • In the tornado program, make it bigger each time the message "resource gathered" is received. To do this, use the command "Change size by …" from the "Looks" category.

  • Because the tornado's size is modified in the program, the size must be initialized at the start of the program using the command "Resize to 100%" from the "Looks" category.


 Activity 5: Making the tornado go faster and faster (20 minutes)

This task, which is very difficult, is intended for older students (middle school). However, some older elementary school students may need a challenge. This should do the trick!

The aim is to make the tornado go faster each time a resource is gathered (ice or plant). To make the tornado go faster, a variable – "speed_tornado" – must be created (initialized at 1, in the same program as for the other variables) and to increase it, such as by 10% at each event (hint: increasing the speed by 10% equates to multiplying by 1.1).

The tornado program is modified as follows:

Note that the value of "speed_tornado" must be taken into account in the program that commands its movement ("Glide" instruction). This can be done by including "speed_tornado" in the glide time calculation as follows:



The greater the "speed_tornado", the faster the movement is: the tornado gets faster and faster, which is the result we want.


 Activity 6: Simulate a torus world (joining the edges of the backdrop) (20 minutes)

The game will be more fun if the rover is not blocked by the edges of the backdrop. When it reaches the right edge, it needs to continue along its path and reappear on the left side, and vice versa. It should do the same for the top and bottom edges.

Scientific notes:

  • A flat surface that is folded so that the left and right edges meet is called a cylinder. If a second fold is added to join the top and the bottom edges, this is called a torus cylinder. It resembles a doughnut.
  • Many video games are based on a torus world, even if it does not actually resemble a real planet (on Earth, when you reach the North Pole, you do not switch to the South Pole!).

The teacher lets the students work on their own and guides them if they encounter difficulties, first explaining the algorithm to use: if position X of the rover goes past 240 (far right edge), then it must go to -240 (far left edge). Next, the teacher can show the different blocks required to build the program: a "repeat forever" loop, a, "if…then" control structure, a "higher than" operator, the value for variable X (blue "Position X" block), and the instruction to be able to change this value "blue "Set X to …"). The blocks connect together as follows:



Teaching note
Depending on the shape of the sprites, it may be necessary to leave a small margin (instead of setting the edge value at 240, set it at 235).

Once the students have understood how to program the transition from the right to left edges, it is easy to program the transition from left to right and then vertically (Y variable) top to bottom and bottom to top.

The rover script that creates a torus world is:

Teaching notes:

  • The screenshot above shows that it is possible to add comments to a program. It is good to get into the habit of doing this to make the program clearer for both you and those who will be reading it.
  • At this point, the instruction "bounce back if the edge is touched" needs to be deleted in the scripts that pilot the rover using arrows.


 Activity 7: Preventing resources and traps from overlapping (20 minutes)

Like for Activity 5 above, this task is aimed at middle school students or older elementary school students who are ahead of the rest of the class.

When resources (ice, plants) are gathered, they reappear randomly on the stage. It is quite possible that a resource will appear where there is already a trap (dune or lava). This situation must be avoided, as you cannot have two contradictory goals: gathering the resource and avoiding the obstacle.

What do you do to ensure this does not happen? A new position must be chosen randomly as long as the resource is touching a trap. However, because the resource was not initially in contact with a trap, the loop will not run. The trick is to introduce a preliminary step to force the loop to run a first time. The algorithm is:

1. Place the resource anywhere by randomly selecting its coordinates (or, if you prefer, place it on a trap).

2. Then, create the following loop: Until the resource is in position free of any traps, it assigns a new random position.

The students will need to be guided, either by telling them the trick above (after letting them explore on their own) or by giving them the final program and asking them to analyze it to understand what it does and why.

The final program for the ice or plants is:



Conclusion and lesson recap activity

The video game is now interesting enough for students to play it and give each other challenges.

The students update the list of Scratch instructions they know.

The teacher reviews with the class what they learned during this project, the difficulties they encountered, what they enjoyed (some will likely have already started creating other Scratch programs at home), etc.

Teaching notes

  • This programming activity was probably new to most students. To make sure they do not forget how to use Scratch and to encourage their creativity, we suggest having them create a personal project later in the year. This can be a video game (a fairly complex project, as we saw), an animated card (for Halloween, Christmas, etc.) or interactive surveys. There are many possibilities.
  • The aim of the next step is to explore some of the additional functionalities in Scratch to give you an idea of other possible activities.



<< Step 2.7 Sequence II Step 2.9 >>


Project partners

Aucun résultats