Step 1: Adding to the Player’s Run Speed

Goal:


The first thing we need to do is add to the player’s run speed when the space key is pressed

We will need to constantly check for this until “Winner” > 0

Winner is a variable. Variables are something that can hold a piece of information that can be used multiple times in our code.

When we have a Winner, we assign the “Winner” variable a racer number (1-4). Therefore, if “Winner” is greater than 0 then we don’t want to add to the player’s run speed anymore.

Steps:

  1. Select the “Player” sprite (the other sprites have a lot of other code we shouldn’t mess with at the moment)
  2. From Events, place a when I receive block
  3. Set the message for the when I receive block to be “StartRace!”
  4. From Control, place a repeat until block
  5. From Operators, place a > block inside the repeat until block
  6. From Variables, place a round Winner” block on the left side of the > block
  7. Type in 0 on the right side of the > block
  8. From Control, place an if then block inside the repeat until block
  9. From Sensing place a key pressed block inside the if then block
  10. In the key pressed block set the key to be space

Code: