Step 3: Movement Code Cont’d

Goal:


Let’s finish up Iron Man’s movement code.

When the player presses the space key, The Y variable needs to be brought back to a positive number allowing Iron Man to fly upward.

Steps:

  1. Still on the Iron Man sprite, From Motion, place a Point in direction block to continue the forever loop.
  2. From Operators, add a subtraction block into the point in direction block.
  3. In the equation, change the first number to 90 then click on Variables and add a Y block for the second number.
  4. From Control, add an IF statement below the point in direction block.
  5. Click on Sensing and add a Key space pressed block into the condition of the IF statement.
  6. Lastly, from Variables, place a set highscore to block inside the if statement. Remember to click on highscore ,change the variable to Y. and set the last bubble to 4.

Code: