Step 4: Move Down

Goal:


Moving down on the screen is very similar to moving up, but we need to change our speed to reflect the direction we are going in.

Our speed is a positive number which means that, if we leave it the way it is now, we will move up if we put it in a change y by block. What we want to do is to move down (negative y direction).

So we are going to turn our speed block into a negative number any time we want to move down. We can do this by multiplying speed by -1. When we do this and add our speed to the X-Wing’s y coordinate we are actually subtracting or moving down.

Let’s code our down movement (negative y direction)..

Steps:

  1. From Control, place an IF statement block.
  2. From Sensing, place a key space pressed block.
  3. Click on the triangle to open up the menu and select down arrow.
  4. From Motion, place a change y by block.
  5. From Operators, place a *(multiply) block and set the right side to -1.
  6. From Variables, place a round speed block into the left side of the *(multiply) block.

Code:


Click to replay