Project 442: Infinite Flying Game

4. Program a penalty for falling off the screen

The game should stop if you let your main character fall - or fly too high up.
Starting point file for this challenge

Your goal

Steps

1. Start a new piece of code with an if-statement

Grab a yellow "when green flag clicked." Next, grab the if-statement block we used before. 

2. Check if the hero's Y position is less than -170

The bottom most part of the screen on Scratch is -180, so if the hero goes below -170, it's definitely off the screen. 

Grab a green "operators" block, " ___ < ___." In the first blank, check the hero's "y position" (a dark blue block.) In the second blank, type -170. 

Put this green block into the "if" blank of the if-statement. 

3. Add a "stop all" block as a result

Put a "stop all" block in the "then" part of the if-statement. This block is found in the "control" section. 

4. Test it out!

Make sure the game ends if you touch the bottom of the screen before moving on to the rest! Click the green flag to test things out. 

5. Repeat last 2 steps, but for the top of the screen

The top of the screen in Scratch is 180, so we want to check if the hero's y position is above 170. If so, then stop the game again. 

6. Repeat your code with a forever loop

Currently, the game is only checking if the player is out of bounds at the start of the game, but if you put a forever loop around the entire code, the game will check for the whole game.