Step 3: Moving the Fish

Goal:


We set the speed variables to a certain random value, but we have not coded the fish to do anything with those values yet.

Let’s now make the fish move at the variable speed once it has chosen a random value.

However, if we played the game right now, the fish will get stuck on the walls because it will forever move at that speed value.

Steps:

  1. Stay on the “Fish” sprite.
  2. From Control, place a forever block.
  3. From Motion, place a change x by block.
  4. From Variables, place a round xSpeed block inside the change x by block.
  5. From Motion, place a change y by block.
  6. From Variables, place a round ySpeed block inside the change y by block.

Code: