How to Make a Pac-Man Game in Scratch: A Step-by-Step Guide for Beginners
Pac-Man is one of the best first games to build in Scratch because every system in it is small: move, bump into walls, eat things, get chased. This guide walks through a complete, playable version in ten steps. You don't need any prior Scratch experience — just a free account at scratch.mit.edu.
Before you start
Two decisions make everything easier later. First, draw your maze walls in one solid colour (say, dark blue) and use no other blue anywhere — Scratch's touching color block is how we'll detect walls. Second, keep Pac-Man's movement speed a number that divides evenly into your corridor width (if corridors are 30 pixels wide, move 2, 3 or 5 steps at a time) so he lines up with the grid.
Step 1 — The maze backdrop
Click the Stage, open the Backdrops tab, and draw a maze with the rectangle tool in your wall colour. Leave the corridors black or white. Keep it simple for the first version: an outer border, a few inner blocks, and one gap on each side for the tunnel.
Step 2 — The Pac-Man sprite
Delete the cat. Paint a new sprite: a yellow circle with a wedge cut out. Duplicate the costume and close the mouth on the copy so you have two costumes — open and closed — for the chomping animation. Set the rotation style to all around so he faces the direction he moves.
Step 3 — Arrow-key movement with wall collision
In Pac-Man's code area:
when green flag clicked
go to x: 0 y: -100
forever
if key right arrow pressed then
point in direction 90
move 3 steps
if touching color [blue] then move -3 steps
if key left arrow pressed then
point in direction -90
move 3 steps
if touching color [blue] then move -3 steps
(repeat for up = 0 and down = 180)
next costume
wait 0.05
The trick is in the two move blocks: step forward, and if that put you inside a wall, step straight back. It looks like you never moved.
Step 4 — The dots (using clones)
Paint a small white circle sprite called Dot. Hide it, then create clones at each grid position:
when green flag clicked
hide
set [dots left] to 0
set y to 140
repeat 10
set x to -200
repeat 14
if not touching color [blue] then
create clone of myself
change [dots left] by 1
change x by 30
change y by -30
when I start as a clone
show
wait until touching [Pac-Man]
change [score] by 10
change [dots left] by -1
delete this clone
Make score and dots left variables for all sprites. The if not touching blue check stops dots spawning inside walls.
Step 5 — A ghost that chases
Paint a ghost sprite. The simplest working AI: move, and when you hit a wall, turn.
when green flag clicked
go to x: 0 y: 60
forever
move 2 steps
if touching color [blue] then
move -2 steps
turn right (pick random 1 to 3) * 90 degrees
To make it feel like Blinky, add a second script: forever → wait 3 → point towards Pac-Man. The ghost will now head your way every few seconds, then bounce around walls between decisions. Our ghost guide explains what the four real ghosts do if you want to build them properly.
Step 6 — Lives and getting caught
Make a lives variable set to 3. In Pac-Man's forever loop add:
if touching [Ghost] and not frightened = 1 then
change [lives] by -1
go to x: 0 y: -100
wait 1
if lives = 0 then
say [Game over]
stop all
Step 7 — Power pellets
Paint a bigger dot called Power Pellet and place four by hand. When Pac-Man touches one: broadcast frightened, set frightened to 1, wait 7 seconds, set it back to 0. In the ghost: when I receive frightened → switch costume to blue → wait 7 → switch costume to normal. Then in Pac-Man: if touching Ghost and frightened = 1 → change score by 200 → broadcast ghost eaten, and have the ghost go back to its start on that message.
Step 8 — Winning
In any sprite: wait until dots left = 0 → say "You win!" → stop all.
Step 9 — Sound
Add a short sound from the Scratch library (the "pop" works) and play it in the Dot clone script before it deletes itself. Add a longer one for game over.
Step 10 — Polish and share
Common improvements: a second ghost with a different colour and turn rule; a tunnel (when x > 240, set x to -240); fruit that appears when dots left hits 100; and a high-score variable. When it works, click Share and send the link to friends.
Common problems
- Pac-Man gets stuck in walls — your speed doesn't divide into the corridor width, or the sprite's costume is bigger than the corridor. Shrink the costume.
- Dots spawn inside walls — the wall colour in the check doesn't exactly match the backdrop. Use the eyedropper in the touching color block.
- Ghost vibrates in a corner — add a tiny random turn even when not touching a wall, or move it further back after a collision.
The same design transfers almost line-for-line to Python with the pygame library if you want a next step. And if you'd rather study the real thing first, Classic Pac and How Pac-Man actually works are the references we'd use.