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:
- Select the “Player” sprite (the other sprites have a lot of other code we shouldn’t mess with at the moment)
- From Events, place a when I receive block
- Set the message for the when I receive block to be “StartRace!”
- From Control, place a repeat until block
- From Operators, place a > block inside the repeat until block
- From Variables, place a round “Winner” block on the left side of the > block
- Type in 0 on the right side of the > block
- From Control, place an if then block inside the repeat until block
- From Sensing place a key pressed block inside the if then block
- In the key pressed block set the key to be space