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. Faire monter et descendre le perroquet

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 Retour
Suivant arrow_forward
Instructions
  1. Ajoute une instruction Si-sinon et un bloc "Touche espace appuyée" à ton programme qui font que le lutin se déplace vers le haut et le bas lorsque l'utilisateur appuie sur la barre d'espace et la relâche.
  2. Programme la condition "Si" pour se déplacer de 5 sur y, et la condition alors pour se déplacer de - 5 sur y.
  3. Ajoute des changements de costume pour donner au lutin un aspect plus réaliste quand il monte et descend.