Step 2: Adding to the Player’s Run Speed (Continued)

Goal:


Next, we need to code the sprite to change his runSpeed by 1 everytime the spacebar is pressed.

Then we will wait for a moment and then check when the space key is not pressed. Why is this here? What would happen if it wasn’t?

We don’t want the player to hold the spacebar forever to win the race!

After this step the player will gain speed, but won’t move yet. Don’t worry, we’ll do that next!

Steps:

  1. From Variables place a change by block in the repeat until block.
  2. In the change by block, select “runSpeed” and set the number to 1
  3. From Control place a wait block
  4. In the wait block, type in 0.75
  5. From Control place a wait until block
  6. From Operators place a not block inside the wait until block
  7. From Sensing place a key pressed block inside the not block
  8. In the key pressed block set the key to be “space”

Code: