Skip to content

Please update your browser

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

3. Den Papagei aufsteigen und fallen lassen


In the previous step, you should have programmed all three cave sprites to scroll across the screen. In this step, you’ll use an if-else statement to program the player sprite’s flight. Watch this screencast to learn the steps needed to do this, then try it on your own. In this game, the sprite goes up when the user presses the spacebar. If the user does nothing, the bird falls. Programming this requires an if-else statement. If-else statements are used to instruct the computer: In this program, the code will read: To program this, drag out an if-else statement and put it inside the "forever" block.

Remember, every if-else statement needs a condition. To add a condition here, select sensing and a “space key pressed” block.

If the user presses the spacebar, the parrot should move up, so add a “change y by 5” block for the "if". If the user is not pressing the spacebar, the sprite should move down, so add a “change y by -5” block to the else.

Now this reads: Time to test your code! Remember, computer scientists like you test their code often as they program to make sure everything is working the way they want it to. Click the block stack to run it, then hold the spacebar. What happens? The sprite should move up when you press the spacebar, and move down when you let it go.

Nice! Now that the sprite moves up and down, you could add a costume change to make it look like it’s flying. This will look different, depending on the sprite that you chose to be your player.

In the next step, you’ll program a winning and losing condition for your game.

arrow_backward Zurück
Weiter arrow_forward
  1. Fügt eine „falls-sonst“-Anweisung und einen Block „Leertaste gedrückt?“ zu eurem Programm hinzu. Dadurch wird die Figur nach oben und nach unten bewegt, wenn der Benutzer die Leertaste drückt und wieder loslässt.
  2. Programmiert die „falls“-Bedingung so, dass y um 5 erhöht wird, und die „sonst“-Bedingung so, dass y um -5 erhöht wird.
  3. Lasst die Spielfigur das Kostüm wechseln, damit es realistischer aussieht, wenn sie nach oben und nach unten fliegt.