What it shows
The sprite reads the colour under it with the touching colour block, so you can draw any maze and the game still works. It shows how input from the keyboard turns into movement.
The science
The keyboard and the colour sensor are inputs, the blocks are the program, and the moving sprite is the output. The touching colour block compares the colour under the sprite with one you pick using the eyedropper, so walls of one colour act as barriers. Moving the sprite back to the start after a hit is a simple rule that makes the game fair.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A computer, laptop or phone with a browser (free)
- Scratch 3 in the browser at scratch.mit.edu (free, no sign-in needed to code)
- A paint-style backdrop made in the Scratch editor
- A notebook and a pencil
Safety
This project uses safe, everyday materials. Still, read the rules below with a parent before you start.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Open the Backdrops tab and, with the Line tool and a thick width, draw maze walls in dark blue with a gap path, and a green square as the goal.
Choose a small sprite such as a Ball and shrink it with the Size box in the sprite panel so it fits the paths.
Build: when green flag clicked, go to x: -200 y: -150 to place it at the start.
Add four when key pressed blocks: for the up arrow use change y by 5, down arrow change y by -5, right arrow change x by 5 and left arrow change x by -5.
Start another script: when green flag clicked, forever, if touching color (dark blue)? then go to x: -200 y: -150. Pick the colour with the eyedropper from your wall.
Add a second if inside the forever: if touching color (green)? then say You won! for 2 seconds and stop all.
Play and test; if the ball slips through a wall, make the walls thicker or move in steps of 3 instead of 5.
Draw a harder maze on a new backdrop and use switch backdrop to to show level 2 after winning.
What you should see
The ball moves with the arrow keys, goes back to the start each time it touches a wall and shows You won! when it reaches the green goal.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1How does the sprite know it hit a wall?
The touching colour block checks if the sprite is on the wall colour.
2Why must the colour be picked with the eyedropper?
The block matches an exact colour, so a slightly different shade would not be detected.
3Which part is input and which is output?
Key presses are input; the sprite moving on the stage is output.
4Why use small steps?
Big steps can jump over a thin wall without touching it.
Take it further
Add a Timer display using the timer reporter and keep the best time in a variable.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Computer & office
Computer Fundamentals Study Book
The complete study notes, practice questions and glossary for Computer Fundamentals
