Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

2. Lancer un lutin


In the previous screencast, you should have added one sprites to the starting project.

If you haven’t done this yet, please pause this screencast and do so now.

In this screencast, you’ll program the player sprite to “launch,” or repeatedly move forward, when the spacebar is pressed and program the arrow keys to control left and right turns. Go ahead and watch this screencast first to learn how to do it, then you’ll get the chance to try it on your own. First, you need to create a program that will cause the sprite to move when someone presses the spacebar.

You can do this by adding a “when space key pressed” event and a “move 10 steps” block.

Test that code to see how it works.

Good! But, you want the sprite to “launch” when the space key is pressed, meaning that it will keep moving forward without stopping.

Click on control.

You don’t need the sprite to repeat moving forward forever, just until it reaches the finish line. So select a “repeat until” block, and place it around the “move 10 steps” block. The sprite should repeat moving forward until it touches the finish line. Click the sensing menu, drag a “touching” block into the “repeat until” block, and change the value to “finish line.”

Check what happens when you test the code.

The sprite moves forward and stops once it reaches the finish line.

That’s fine. But how could the game be played again?

Sometimes problems become obvious when you test your code. As a computer scientist, it’s important to test your code often so these kinds of problems.

To make it so the player can continue playing the game, you can use a “go-to” block to move the sprite back to the start.

Drag the sprite to where you want it to start, then place the “go-to” block below the “repeat until” block.

Now, when you press the spacebar, the sprite moves forward until it reaches the finish line, then it goes back to the start.

In the next screencast, you’ll program the sprite to turn left and right with the arrow keys.

arrow_backward Retour
Suivant arrow_forward
  1. Sélectionne un lutin pour le joueur 1 et crée un évènement qui se produira lorsque la barre d'espace est appuyée.
  2. Ajoute un bloc "Mouvement" pour faire avancer le lutin.
  3. Ajoute un bloc "Répéter jusqu’à" à la pile.
  4. Ajoute un bloc "Ligne d'arrivée touchée" comme condition.
  5. Définis une position de départ pour ton lutin avec un bloc "Aller à".