Learn · Scratch

How to Make a Snake Game on Scratch

How to Make a Snake Game on Scratch

No coding experience needed — Scratch is blocks, not typing. In about 30 minutes you will build a real snake game: a head that moves on a grid, body segments that follow it, food to eat, and a score. This is the same game logic our Python tutorial teaches, just with puzzle-piece blocks instead of code.

Open scratch.mit.edu in a new tab and follow along.

Setting up your sprites (snake head, body segment, food)

You need three sprites:

  1. Head — click the cat icon → Paint. Draw a filled green square about 20×20 pixels in the centre of the paint editor. Name the sprite Head.
  2. Segment — paint another green square, slightly darker. Name it Segment.
  3. Food — paint a red circle roughly the same size. Name it Food.

Delete the cat sprite when you are done.

Next, set up two variables. Click VariablesMake a Variable:

  • score
  • direction

Also make a list called positions — we will use it to remember where the head has been so segments can follow the exact path.

Movement blocks explained

Snake movement is stepped, not smooth: every fraction of a second the head snaps to the next grid cell. We do this with a timer loop instead of the forever-loop, so the speed stays constant.

Click Head and build this script:

when green flag clicked
hide
go to x: (0) y: (0)
set [direction v] to (right)
delete all of [positions v]
set [score v] to (0)
show
forever
    add (x position) to [positions v]
    add (y position) to [positions v]
    move (20) steps
    wait (0.3) seconds
end

Wait — one problem: move 20 steps keeps moving in the same facing direction. Add these two scripts to Head so arrow keys change direction:

when [right arrow v] key pressed
if <not <(direction) = (left)>> then
    set [direction v] to (right)
    point in direction (90)
end

when [left arrow v] key pressed
if <not <(direction) = (right)>> then
    set [direction v] to (left)
    point in direction (-90)
end

when [up arrow v] key pressed
if <not <(direction) = (down)>> then
    set [direction v] to (up)
    point in direction (0)
end

when [down arrow v] key pressed
if <not <(direction) = (up)>> then
    set [direction v] to (down)
    point in direction (180)
end

See what the if not does? It blocks a 180° reversal — the number-one bug in beginner snake games. Our web version solves the same problem with something called an input buffer; here the simple "no instant U-turn" rule is enough.

Detecting collisions in Scratch

Three collisions make snake snake: walls, your own body, and food.

Walls — add to the bottom of Head's forever loop:

if <<(x position) > [230]> or <(x position) < [-230]>> then
    broadcast [game over v]
stop [this script v]

and a matching check for (y position) > 170 / < -170.

Food — food gets its own scripts rather than living inside Head's loop:

when green flag clicked
forever
    go to x: (pick random -220 to 220) y: (pick random -160 to 160)
end

when I receive [new food v]
go to x: (pick random -220 to 220) y: (pick random -160 to 160)

and inside Head's forever loop, add the scoring check:

if <touching [Food v] ?> then
    change [score v] by (10)
    broadcast [new food v]
end

Self collision — the honest answer is that self-collision in Scratch needs the clone technique: each time the score changes, create one clone of Segment, and each clone reads its position from the positions list a little further behind the head. When the head touches any clone, game over. In Segment's script area:

when I start as a clone
show
forever
    if <touching [Head v] ?> then
        broadcast [game over v]
    end
end

Cloning is the most advanced idea in this guide — take it slowly, and treat it as an optional stretch goal. A perfectly fun version of snake exists with just walls + food.

Adding score and restart logic

Almost done:

  1. Add a Game Over backdrop message: click Stage → Backdrops → paint a dark rectangle with the words "GAME OVER". Show it via
when I receive [game over v]
switch backdrop to [game over v]
wait (2) seconds
switch backdrop to [backdrop1 v]
  1. Restart cleanly: the green-flag scripts above already reset score, position, direction, and the positions list, so clicking the flag starts a fresh run.
  2. Display the score: drag the score variable onto the stage so it shows as a readout while playing.

Press the green flag and play. If the head moves but food never scores, double-check that the touching Food? block is inside Head's loop, not Food's.

What you learned

  • Stepped grid movement with a timed loop
  • Blocking instant reversals (the input-buffer idea, simplified)
  • Three collision types: wall, food, self
  • Score variables, broadcasts, and restart flow

When you outgrow Scratch, the Python version is the natural next step — same logic, typed out for real. Or play a few rounds of Classic Snake here to see how far the same mechanics can be pushed.

Ready for typed code next? The Python snake tutorial rebuilds this same game line by line — or just play a round here.