Step 4: Moving the Shark

Goal:


Now let’s code the Shark’s movement.

As long as we still have lives in the game, we will be able to control the Shark’s movement.

Steps:

  1. Now click on the “Sharky” sprite.
  2. From Events, add a when I receive block for the “GameStart!” message.
  3. From Control, add a repeat until block.
  4. From Operators, place a < block and set the left side to Lives: and the right side to 1.
  5. From Control, place 4 if statements stacked on top of each other, these will be used to control the Shark’s movement.
  6. From Sensing, place a key space pressed block into each if statement and change it so that all for arrow directions are in the code.
  7. From Motion, place a change y by block for the up and down arrow key if blocks.
  8. Place a change x by block for the left and right arrow key if blocks.
  9. Change the numbers to negative for the left arrow key and the down arrow key if blocks.

Code: