In the previous step, you should have programmed all three cave sprites to scroll across thescreen. In this step, you’ll use an if-else statement to program the player sprite’sflight. Watch this screencast to learn the steps needed to do this, then try it on yourown. In this game, the sprite goes up when theuser presses the spacebar. If the user does nothing, the bird falls. Programming thisrequires 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 acondition. 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 oftenas they program to make sure everything is working the way they want it to. Click theblock stack to run it, then hold the spacebar. What happens? The sprite should move up whenyou 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 itlook like it’s flying. This will look different, depending on the sprite thatyou chose to be your player.
In the next step, you’ll program a winning and losing condition for your game.