Scratch: Building an Interactive Game

Look at this race track from above. Imagine it as a Scratch backdrop: a grey road, green grass and a finish line. Could you program a car that you steer with the arrow keys, that gets sent back if it drives onto the grass, and that tells you your lap time? By the end of this post, you can.

A satellite photo of a winding motor-racing circuit with grandstands and car parks, surrounded by fields.
A satellite view of the Circuit of the Americas, a Formula One race track in Texas, USA. From above, a race track looks a lot like a game backdrop.

Image source: File:Circuit of the Americas, April 22, 2018 SkySat (cropped2).jpg (Wikimedia Commons)

In this post:

  • How a keyboard controls a game
  • Four new tools: the timer, reset timer, touching colour and sounds
  • Step-by-step plan for a car racing game
  • Play a car racing game in this post and see its scripts light up
  • Group project checklist, a matching activity and a quiz

Brainstorm: keys that control games

With your group, list games you know and the keys they use. Common choices: arrow keys to move or steer, W A S D for a second player, space to jump or shoot. For a racing game, the up arrow could move forward and the left and right arrows could turn. What should happen when the car leaves the road? How will the player know their time?

New tools for games

BlockCategoryWhat it does
timerSensingCounts the seconds since the project started or since it was last reset. Tick it to show it on the stage.
reset timerSensingSets the timer back to 0, for example when a race starts.
touching color [ ]?SensingTrue when the sprite touches that colour. Click the colour box, then use the dropper to pick a colour from the stage.
start sound [ ] / play sound [ ] until doneSoundPlays a sound. start sound lets the script carry on at once; play sound until done waits until the sound finishes.

Plan: a car racing game

Step 1 – Backdrop: paint a track. Make the road one colour (grey) and everything off the road another colour (green grass). Add a finish line across the road as a separate, thin sprite.

Step 2 – Car sprite: paint a small car from above, or choose one from the library. Make it point to the right in its costume so that direction 90 means “forward”.

Step 3 – Steering: the up arrow moves forward and the left and right arrows turn:

when [up arrow] key pressed
    move (10) steps
when [right arrow] key pressed
    turn ↻ (15) degrees
when [left arrow] key pressed
    turn ↺ (15) degrees

Step 4 – Off the track: when the car touches green, send it back to the start and play a crash sound:

when green flag clicked
go to x: (start x) y: (start y)
point in direction (90)
forever
    if <touching color [green]?> then
        start sound [crash]
        go to x: (start x) y: (start y)

Step 5 – Timing: reset the timer at the start and show the time at the finish line:

when green flag clicked
reset timer
forever
    if <touching [Finish line]?> then
        say (join [Your time: ] (timer)) for (2) seconds
        stop [all]

Step 6 – Sounds: add a sound when the race starts, when the car crashes and when it finishes.

Step 7 – Instructions and game over: have a sprite say the instructions at the start. Decide when the game ends: when the car finishes, or when the timer passes a time limit.

Be careful: if the finish line is touching the car at the start, the game will end straight away! Put the car just behind the line, or only check the finish line after the car has driven part of the way round (a variable such as halfway can help).

Activity: race!

Try it: drive one lap

Click the green flag button, then click the track and drive with the arrow keys (or hold the on-screen buttons). The scripts on the right light up when they run. Can you get round without touching the grass? What is your best time?

Scripts running now

when [up arrow] key pressed
    move (10) steps
when [right arrow] key pressed
    turn ↻ (15) degrees
when [left arrow] key pressed
    turn ↺ (15) degrees
forever
  if <touching color [green]?> then
    start sound [crash]
    go to x: (start) y: (start)
if <touching [Finish line]?> then
    say (join [Your time: ] (timer))

timer: 0.0

This game was written in JavaScript so it can run inside this page, but it follows exactly the same plan as the Scratch scripts above: keys move and turn the car, a forever check on the colour under the car sends it back to the start, and the timer is reported at the finish line.

Watch: make a race game in Scratch

This tutorial walks through building a race game in Scratch. Pause it often and build along with it.

Video: How to Make a Race Game in Scratch [15 Min Tutorial] – CodeSpeak Labs – https://www.youtube.com/watch?v=tFQkv1GJsoc

Activity: which block does the job?

Try it: match the job to the block

Choose the block you would use for each job in the racing game.

Send the car back when it drives onto the grass
Start counting the seconds again when the race begins
Make a crash noise
Show how long the lap took
Turn the car when the right arrow is pressed
Move the car forward

Group project: build your racing game

In groups, build your own racing game in Scratch (or another interactive game controlled by the keyboard). Use this checklist to test each other’s games:

FeatureDone?
The car moves forward and turns using the keyboard
Touching the off-track colour sends the car back to the start
The timer resets at the start of the race
The time is shown when the car reaches the finish line
At least two sounds are used (start, crash or finish)
Instructions appear at the start
The game ends properly (finish line or time limit)
Sprites and backdrops have clear names

Extension: duplicate the car for a second player, using W, A and D, and see who finishes first.

Self-check quiz

Click the best answer. You get feedback straight away; only your first click counts towards your score.

1. Which block sets the timer back to 0?

2. Which block can tell when the car drives onto the green grass?

3. Why does the touching-colour check go inside a forever loop?

4. What is the difference between start sound and play sound until done?

5. Which block shows the time at the finish?

6. The game ends as soon as it starts. What is the most likely problem?

Related posts on islandclass.org

Next: Scratch: Reading Code and Predicting Output

Syllabus link: Forms 1–3 ICT curriculum, Module 5, Objective 5.16 – develop interactive games.

Attributions to media used in this post:

Updates

2026/10/21

– Fixed the activity code so its buttons keep working.

© 2026 Vedesh Kungebeharry. All rights reserved.

Leave a Reply