One of the most fun things in scratch is Sensing. This means being able to detect when one sprite makes contact with something else, for example, another sprite. Once you have finished this tutorial you will have the skills to begin planning the design of your first basic game!

Starting point

The final code from the Walk the dinosaur tutorial (first image below) is your starting point.

Dragging a Scratch code block from a Scratch program.
  1. We need to remove the and code block and all its conditions.
  2. Hover just above the and and left-click grab.
  1. Drag the entire and code block out of the code.
  2. Right-click on the block.
  3. Select Delete 5 blocks.

Add the Rocks sprite

  1. Click on the Choose a Sprite button in the Sprite panel.
  2. Search for and add the Rocks sprite.
  1. The Rocks sprite is now present on the stage.
  2. Drag it into position on the stage or set the 𝚡 & 𝚢 coordinates in the Sprite settings panel.
  3. The Rocks sprite must be in the path of the dinosaur.

Add a Sensing code block

Adding a Sensing Scratch code block to a Scratch program.
  1. Add the touching ... ? code block from the Sensing category.
  2. Select the Rocks sprite from the dropdown of the touching ... ? code block.
Adding a Looks code block to a Scratch program.
  1. Add a say ... for ... seconds code block.
  2. Type Ouch! into the first input and 2 into the second input.

Run

  1. Click the dinosaur sprite.
  2. When the dinosaur sprite hits the rock, it stops and exclaims “Ouch!”.
  3. The message disappears after 2 seconds.

Next steps

What happens if you want the second sprite to react to being hit by the first sprite? We will need to Broadcast & Receive messages in Scratch.

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher who has just finished training as a Young Engineers instructor. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.