Step 2:Movement Code Cont’d

Goal:


Loops are a container for sets of repeating instructions until certain conditions are met.

Variables are words or phrases we can use to represent bits of information like numbers. We do this so the information stays consistent through the program and is easy to locate.

The “highscore” variable will be used to keep track of the most points achieved in one life.

The “score:” variable will be used to keep track of the current score in the game.

The “Y” variable will be used to represent a constantly decreasing altitude.

Steps:

  1. From Control add a wait until block under the starting code
  2. From Sensing add a key space pressed into the wait until block. Or Space Key will control Iron Man’s jumps.
  3. From Control add a forever loop under the wait until block.
  4. Click on Motion and place a change y by block into the forever loop.
  5. Click on Variables and place a Y block into the change y by block.
  6. Also place a change highscore by block under the block.
  7. Make sure to change the highscore variable to Y and set the number to -1.2. This will make the loop constantly subract from Y and make iron man slowly fall if no space key is pressed.

Make sure all variables are checked in the Variables tab!

Code: