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. Far andare il pappagallo su e giù

Transcript

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 Indietro
Avanti arrow_forward
Istruzioni
  1. Aggiungi un'istruzione "Se-altrimenti" e un blocco "Quando si preme il tasto spazio" al tuo programma per far muovere in su e in giù il programma quando l'utente preme e rilascia la barra spaziatrice.
  2. Programma la condizione "Se" per muovere y di 5 e la condizione Altrimenti per muovere y di -5.
  3. Aggiungi dei cambi di costume per rendere l'aspetto dello sprite più realistico mentre vola su e giù.