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. Eine Figur einführen


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 Zurück
Weiter arrow_forward
  1. Wählt eine Figur für Spieler 1 aus und erstellt ein Ereignis, das ausgelöst wird, wenn man die Leertaste drückt.
  2. Fügt einen Block „bewege dich“ hinzu, um die Figur nach vorne zu bewegen.
  3. Fügt einen Block „wiederhole bis“ zum Stapel hinzu.
  4. Fügt einen Block „wird Ziellinie berührt“ als Bedingung hinzu.
  5. Legt eine Startposition für eure Figur mit einem Block „gehe zu“ fest.