Step 2: Initializing the Fish’s Speed

Goal:


The fish will be swimming at different speeds and it has two different costumes that make it look towards the left or towards the right.

When the game starts, we will set the fish to be looking towards the right.

We also need to set our speed variables to pick a random speed to travel at when the fish spawns into the game.

Lastly, if the fish is moving to the left (the negative x direction), we want the costume to change and make the fish look towards the left.

Steps:

  1. Stay on the “Fish” sprite.
  2. From Events, place a when green flag clicked block.
  3. From Looks, place a switch costume to and change it to fish2.
  4. From Variables, place a set to block and change it to xSpeed.
  5. From Operators place a pick random block inside the previous block and set the numbers to -10 and 10.
  6. From Control, place an if block.
  7. From Operators place a < block.
  8. On the left side of the < block, place a round xSpeed block from Variables.
  9. On the right side of the < block set it zero.
  10. From Looks, place a switch costume to block and change it to fish3.
  11. From Looks, grab a show block and place it outside of the if statement.

Code: