1, 2, 3, code ! - Cycle 3 activities - Step 2.3. Operating the rover


The students create their first program, letting them operate the rover using the arrow keys. They learn about the coordinates system.

Key ideas
(see Conceptual scenario)


  • The machines around us merely execute 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.


  • To give machines instructions, we use a programming language, which can be understood by both machines and people.
  • 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 the class

  • Projector
  • Enlarged version (A3 or A4) of Handout 1

For each pair of students

  • A computer with Internet access or, if there is no good connection available, a computer with Scratch preinstalled.

For each student

Once each pair has successfully imported their program (which so far contains only the rover and backdrop), the class goes back over the list of steps needed to program the video game. The first thing to do is to drive the rover. The simplest way is to drive the rover using the keyboard arrow keys.

Teaching note:
The students will again need to be guided during this step. They will then have learned the reflexes they need to be more independent, and each pair can progress at its own pace.

 Activity 1: Making the rover move to the left (10 minutes)

The students already know how to move the rover to the right: they just have to tell it to move, as it faces the right by default. Moving it to the left is a little more difficult, as the students first have to ask the rover to point to the left before moving.

They should work independently and feel their way through, with the teacher regularly checking in on groups to ensure nobody is stuck. The teacher can guide them by suggesting looking for a “point” instruction.

Teaching notes:

  • There are two instructions of this type:
  1. “Point towards,” which doesn’t help us as the only available option when you click on the little arrow is “mouse-pointer” (meaning the sprite would point towards the position of the mouse pointer).
  2. “Point in direction...,” which is what we need here. When you click on the number in the instruction (the default number is generally “90”), a help bubble explains that the angle 0 is the top of the screen, 90 is the right, etc.

So here, you need to choose “Point in direction -90”

  • Un exercice en ligne permet de se réapproprier la notion d'orientation. Attention, cet exercice n'utilise pas Scratch.

In the end, the program to move the sprite towards the left is:


 Activity 2: Making the rover move in any direction (5 minutes)

The students should now be able to move the rover in any direction (right, left, up and down) using exactly the same method described above.

Please note: You now need the instruction “point in direction 90” to tell it to go to the right, as the sprite no longer points in that direction by default.


 Activity 3: Driving the rover using the arrow keys (15 minutes)

The students will now make the rover move when they press the arrow keys on the keyboard. They should try to work out how independently. Some will remember the instruction “when green flag clicked,” which they saw during the first Scratch session. That was an event that triggered an action.

Here too, an event is needed: the action is triggered when a key is pressed. The command “when (space) is pressed” is what we need, except “space” should be replaced with one of the arrow keys (right arrow to move to the right). That is done the same way as before:



In the end, the rover’s scripts area will contain four scripts, each describing movement in a specific direction. The program may look like this:


Teaching notes:

  • You can see here that several scripts can co-exist in the same program. Each is executed when the trigger event (here, a key press) is detected.
  • Some students may panic, thinking that their program has disappeared following a misstep. That is generally not the case (the program is not deleted). They have simply clicked on the stage (which has its own scripts area, but which is empty because we have not put anything in there yet) instead of the sprite. Sometimes, they have clicked on the sprite, but have clicked on the “costumes” tab instead of the “scripts” tab. All they have to do is click again on the sprite, and then on the “scripts” tab to display the program once more!

Fourth-grade class of Caroline Vinel (Paris)


 Activity 4: Bouncing off the edges (5 minutes)

The students work out how to make the rover bounce of the edges of the stage. For example, if the rover drives towards the right and reaches the right-hand edge of the screen, it has to bounce back so as not to leave the screen.

That is very easy to do, by adding the instruction “if on edge, bounce” to each of the scripts produced previously. For example:



 Activity 5: Reset the position of the rover (5 minutes)

The teacher reminds the students that, when you start the program (green flag), the rover should be situated at the center of the screen. The students easily remember the instructions they saw during the first Scratch session.



Teaching notes:

  • You can now launch the program by clicking on the green flag. If you prefer, you can hide programs during execution by clicking on the “full screen” button at the top left of the stage.
  • Always remember to save your work!


 Activity 6: Understanding the X and Y coordinates of the rover (20 minutes)

The previous activity demonstrated the X and Y coordinates of the rover, through the instruction “go to X: ... Y: ...” The next steps (resources, traps, etc.) will require students to make use of these coordinates, so it is important to understand how they work.

The teacher asks the students to observe the X and Y coordinates displayed at the bottom right of the stage. They will notice that the coordinates displayed change depending on the position of the mouse.



  • What are the values of X and Y when the mouse is at the center of the stage? (answer: X=0, Y=0)
  • And when the mouse is at the right-hand edge? (answer: X = 240. Y can have any value, depending on the position of the mouse)
  • And when the mouse is at the left-hand edge? (X=-240)
  • And when the mouse is at the top edge? (Y = 180) or at the bottom edge? (Y=-180)

Together, the class concludes that X indicates the position on the horizontal axis (imaginary, invisible axis) and that Y indicates the position on the vertical axis (also imaginary).

The students may realize that, in the “motion” category of the scripts tab, many instructions use the X and Y variables. In these cases, it is not a question of the position of the mouse, but of that of the selected sprite. The rover has its own set of X and Y variables.

The teacher can hand out Handout 2 to each student and suggest some little exercises:

  • Place the sprite on the stage, at the coordinates X =100, Y = 100
  • What happens if you add 50 to X? Where is the sprite now?
  • And what if you now set Y to 0? Where is the sprite?

Teaching notes:

  • To help students understand these coordinates, the teacher can draw a parallel with what the students have already seen in geography: latitude and longitude. Here, the unit is no longer the degree (we aren’t using angles), but the pixel. Similarly, in a game of battleships, ship locations are identified using two coordinates (a letter and a number). Give or take the unit or symbol, this is exactly the same: identifying the position of a point on a surface, which requires two coordinates as a surface is a two-dimensional space.
  • Similarly, it may be useful for certain students to use concrete examples to demonstrate negative numbers. There is no shortage of examples, from dates and temperatures (what is “-10°C”? Is it hotter or colder than “0°C”? And is “-20°C” hotter or colder than “-10°C”?).


Conclusion and lesson recap activity

At the end of this session, it is important to recap the new Scratch instructions the students have learned to use:

  • Point in direction (90)
  • When (space) key pressed
  • When (green flag) clicked
  • Go to (X =…, Y = …)

The students should color these instructions on Handout 1 which they have already used.

Moreover, this session is an opportunity to step back from programming activities and go back over a few concepts:

  • A program is an algorithm expressed in a special language, known as a programming language. These are comprehensible by both machines and human beings.
  • The execution of a program is reproducible (if neither the instructions nor the data to manipulate change, the program always gives the same result).
  • Computers merely execute the instructions they are given, no more, no less.
  • The position of an item on the screen is identified using two coordinates. In Scratch, they are called X and Y. X varies between -240 and 240, while Y varies between -180 and 180.

The students write down these conclusions in their science notebooks. The teacher updates the “Information” section of the poster entitled “Defining computer science.” 



<< Step 2.2 Sequence II Step 2.4 >>


Project partners

Aucun résultats