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. Making the Parrot Rise and Fall

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 Back
Next arrow_forward
Instructions
  1. Add an if-else statement and a "space key pressed?" block to your program that makes the sprite move up and down when the user presses and releases the spacebar.
  2. Program the if condition to move y by 5, and the else condition to move y by -5.
  3. Add costume changes to make the sprite look more realistic as it flies up and down.