Game Design & Development · Tiny-Loop Tutorial · Archetype #4

Tutorial: Maze Game

Grid Movement Wall Collision Goal Detection Pre-built Sprites

This is the exact Maze Game archetype from What Makes a Game? — already built and running below. Play it, then swap the pre-built sprites, wall theme, and maze layout using the panel underneath. You can't break the loop itself; that part is locked. Once you've tuned a version you like, you'll build this same architecture two more times: with Scratch's blocks, then from real scratch in JavaScript.

🗺️ The Architecture

Every tiny-loop game starts as a concept, then gets broken into a core loop, a systems list, and a structure — before anyone touches sprites or colors. Here's the Maze Game's architecture:

🌱ConceptNavigate a grid of walls and reach the goal tile.
→
🔁Core LoopPress a direction → move one tile if it's open → repeat until you reach the goal.
→
🧩SystemsGrid movement, wall collision, goal detection, step counter.
→
🏁Win/LoseReach the goal tile to win. There's no lose state — just fewer or more steps.

The four systems, in order of execution on every key press:

  1. Input system — reads the arrow key pressed and computes the one target tile in that direction.
  2. Wall collision system — checks whether the target tile is a wall; if it is, the move is cancelled and the player stays put.
  3. Step counter system — only counts a step when a move actually succeeds, and compares your total to par, the shortest possible route.
  4. Goal detection system — checks the player's tile against the goal tile every move; matching tiles ends the game.

🎮 Play & Customize

Move one tile at a time with the arrow keys or W A S D (hold to keep moving), or use the touch D-pad. Walls block you completely. Find the path to the goal, and try to match par, the fewest steps possible. Your trail shows where you've been.

Steps: 0 Par —

Keys only work while the game has focus. Click the maze first.

Tune the Game (limited, on purpose)

Content settings change how it looks and apply instantly. Rule settings change how it plays, so the round restarts.

Notice what you can't change here: there's no field for "how wall collision works" or "how the goal is detected." That's the engine — the part every version of this game shares. You're only tuning content, not rewriting architecture. That's the limit, on purpose.

What Move Animation Speed actually touches in the engine: nothing in the rules, which is why it's tagged content. It only picks a duration from a lookup table (180ms / 110ms / 60ms) that the tile-slide animation plays over — the tile-by-tile logic in tryMove() that checks walls and the goal runs exactly the same either way. The Maze Layout and Wall Theme selects swap which grid string and color pair the locked renderer reads; the renderer never looks at what the strings mean, only where the # characters are.

👀 Peek at the Code

The game running above is this code — nothing hidden. It's split into two parts on purpose: a small config object you just edited with the panel, and a locked engine that reads it.

✏️ Config — this is what the panel above edits
const config = {
  player: '🤖',
  goal:   '🔑',
  wall:   'lab',
  layout: 'zigzag',
  moveSpeed: 2
};

👆 This block updates live. Change anything in the panel and the matching value flashes here. There's no separate "demo" version of the code; this is it.

🔒 Engine — locked, shared by every version of this game
function tryMove(dx, dy) {
  const tx = player.col + dx, ty = player.row + dy;

  // 1. wall collision: cancel the move if the target tile is a wall
  if (maze[ty][tx] === '#') return;

  // 2. move succeeds: update position
  player.col = tx; player.row = ty;

  // 3. only count steps that actually happen
  steps++;
  updateHUD();

  // 4. check the goal every successful move
  if (tx === goal.col && ty === goal.row) endGame();
}
This is what "architecture" means in practice: the config is the part of the design doc you filled out in Lesson 1 (goal, mechanic, feedback). The engine is the part no one writes twice — the same movement, wall-collision, and goal-detection systems power every maze game, from this one to the original text-adventure dungeon crawlers.

🧪 Remix Challenges

The panel can only turn the knobs the engine exposes. To change the rules, you change the engine. Each challenge edits one system. Try them in your own copy once you've built it in Lesson 2.

TweakFog of warRenderer only · one condition

Only draw tiles within 2 steps of the player. The maze is identical, but it feels completely different, because you've taken away the map. This is a pure rendering change. The engine never knows.

if (Math.abs(c - player.col) + Math.abs(r - player.row) > 2) continue;
TwistKeys and doorsWall-collision system

Add two new characters to the grid strings: k for a key and D for a door. A door acts like a wall until you're holding a key. Now the shortest path might go away from the goal first.

if (tile === 'D' && !hasKey) return;   // locked
if (tile === 'k') hasKey = true;
TransformInfinite mazesReplace the layouts with an algorithm

The three layouts were made by a recursive backtracker: start in a cell, knock down a wall to a random unvisited neighbour, repeat, and back up when you're stuck. Write that function and every game gets a brand-new maze. The "par" number in the HUD comes from a second algorithm, breadth-first search, which finds the shortest path by flooding outward from the start one step at a time.

🛠️ Now Build It For Real

You've played a working Maze Game and seen exactly how it's built. Next, build this same architecture yourself — twice, in two different tools.

🧩 Step 1 — Build It in Scratch

The "Build the Loop with Blocks" section above already shows the exact scripts — backdrop, sprites, variables, and all four key-press scripts, block by block, in Scratch's own category colors. Open a Scratch tab side-by-side and copy each script exactly; the game should come to life the same way it does here.

Open a blank Scratch project tab →

Want more practice first? The Scratch Team publishes an official Maze Starter project you can open and remix directly.

Open the official Scratch "Maze Starter" project →
⚡ Step 2 — Code It From Real Scratch (Lesson 2) Write this same grid movement, wall collision, and goal detection yourself in plain JavaScript and HTML5 Canvas — no engine, no blocks.