Project 210: Maze Game

7. Code for wall collisions

We can't let our main character cheat and run straight through all the walls. Create code that sends the main character back to the starting position if they touch a wall.
Starting point file for this challenge

Your goal

Steps

1. Add a "when green flag clicked" block to your main character

You can find the block in the yellow "events" section.

2. Add an if-statement block.

In English, we'd say a sentence like, "If the main character touches the wall, then they'll go back to the start." The if-statement block will help us write that in Scratch language. 

It can be found in the orange "control" section. 

3. Add a "touched color" condition

We need to check if the main character is touching the same color as the walls before sending them back to the start. 

Grab the light blue sensing block "touching color" and use the color picker tool to choose the same color as your walls 

4. Add a "go to start position" block

This is in the dark blue "motion" section. Change "random position" to the name of your starting sprite. 

5. Repeat your code with a forever loop

Right now, this code is only checking if your main character is touching a maze wall at the very beginning of the game, but then doesn't check anymore after that. We want it to be checking the entire game! You can find the forever loop in the orange "control" section.