Scratch game making exercise 115

Grapple hook

In this exercise you will programme a grapple hook to enable your character to grapple to another location on the stage or to pull an object towards them.


1. Create a new game, select the stage and add these scripts ..

You can colour the stage if you like. Not too dark, anything except black.



2. We need 2 variables.

  1. When the cat grapples we need to store the distance between the cat and the the mouse-pointer
  2. when the grapple hits an object we need to know whether we want to grapple to it or pull it towards the Cat

Create these variables "for all sprites" ..



3. Select the cat sprite, re-name it "Cat" and set it to "only face left-right" ..

We need the cat to be smaller so there is plenty of room on the stage to grapple. Add these scripts ..

Now add the scripts that will enable the cat to ..

  1. walk around the stage (follow mouse-pointer)
  2. grapple to the mouse-pointer (when the "G" key is pressed)
  3. stand still whilst an object is pulled towards the cat (when the "P" key is pressed)

Study this script carefully. Note how it has three "if" script blocks, one for each action.

Note also the repeat script which uses the "grappleDistance" variable to calculate 8 equal steps towards the mouse-pointer. Remember that "grappleDistance" will contain the distance to the mouse-pointer when the "G" key is pressed. This variable is populated from the Grapple Hook sprite script which you will make next.



4. Use "File>Save as" to save your game. Name it "Grapple hook".



5. Click the "Paint new sprite" button under the stage and paint a simple hook facing right. Ensure it's centre point is placed at it's end ..

Name the sprite "Grapple hook" and then add this script to initialise it ..

You may need to alter the size of the hook later.

Note how this script sets properties for the pen. We will use the pen to draw the grapple line.



6. Add the second Grapple hook script (you don't need to add the comments) ..

Study this script carefully. This script moves the Grapple hook in ten equal steps from the Cat to the mouse-pointer, whilst drawing a black (grapple) line. It does this if you are Grappling to the mouse-pointer position or pulling an object from the mouse-pointer position towards you.


Press the "B" key to test your scripts. Use the mouse-pointer and press "G" to grapple to another position on the stage. The "P" key won't work until we have another sprite to pull towards the Cat.

Press "E" to end your game.



7. Use "File>Save" to re-save your game.



8. We need a sprite that the Cat can pull towards itself with the Grapple hook. Paint a simple object for now, such as this ..

Now add these scripts to the Object sprite ..

You can duplicate these scripts to multiple objects.

Press the "B" key to test your game.

Press "E" to end your game.



9. Use "File>Save" to re-save your game.



10. Well done. You've finished. Could you turn this exercise into a full game?