Step 4 – Deal with hitting the walls
Setting the collision up:
If the sprite hits the wall something bad needs to happen.
The walls are all black, so we can use this as a way of dealing with the sprite hitting them.
- You need to add this code inside the Forever block
- Use an orange IF – THEN block
- Add a light blue touching colour block inside the IF – THEN block
Now the tricky bit
- Click on the colour inside the touching colour block
- This pops out a new window. At the bottom, click on the eye dropper – this lets you click on a colour on the backdrop and select it
- Move your mouse over one of the maze walls until it selects black and click – the colour in the block should turn to black
Take care with the eye dropper tool to pick the right colour.
Dealing with the collision:
Now you need to add code inside the IF – THEN block to say what happens when there is a collision.
You can chose what to do. There are lots of different options and you could combine these or come up with your own ideas.
- The spite could say something
The sprite could go back to the beginning of the maze and start again – use a blue move to block to do this
- The game could end – use an orange STOP block to do this
- You could lose a life – you’ll need to set up a variable to deal with lives if you want to use this option
Or you could do something else. What would make the best game?