Clever Quest Lab ← Games

3D Maze

Walk through a maze in first person, collect keys, open doors and find the glowing exit.

0:00.0Time
0 mWalked
1Level
–Keys

3D Maze

Find the glowing green exit. From level 3, a coloured key opens the door of the same colour.

W S or ↑ ↓ walk, A D step sideways, ← → turn; the mouse looks around after Start (if it stops at an edge, keep pushing to keep turning) - or drag on the view on a touch screen.

W S or ↑ ↓ walk, A D step sideways, ← → turn; after Start the mouse also looks around. If it stops at an edge, keep pushing it there to keep turning.

Drag on the left to walk, on the right to turn.

Mode
Level 1

5 × 5 cells · no keys

WS/↑↓ walk   AD sidestep   ←→ turn   mouse: look around (push it to the edge to keep turning)   M map   F full screen   P/Esc pause

How to play

You start in the top-left corner of a maze, seen at eye level. The exit is a glowing green portal at the end of a dead end, as far from the start as the maze allows. Walk into that last cell and the level is done. The clock runs only while you play.

Levels start at 5 × 5 cells and grow by one cell per side each level, up to 26 × 26. A level always has the same maze, so you can improve your time. From level 3 a coloured key opens the locked door of the same colour: one door on levels 3–4, two on levels 5–6 and three from level 7. Every door blocks the only route to the exit, and its key always lies on your side of it.

Free play builds a new random maze of 8 × 8, 12 × 12, 18 × 18 or 26 × 26 cells, without keys. Your best time for each level and each size is kept in this browser. The map is off at the start; it shows only the parts you have walked through, with an arrow for your position and direction.

Controls

How it works

A perfect maze is a spanning tree

Treat every cell as a point and every possible opening between two neighbouring cells as a line. A perfect maze has exactly one route between any two cells, so it is a spanning tree of that grid: all n cells are joined by exactly n − 1 passages and there are no loops. The game builds it with a recursive backtracker. From the corner it moves to a random neighbour it has not visited yet and removes the wall between them. At a dead end it steps back along its own trail until it finds a cell with an unvisited neighbour. A seeded random number generator makes this repeatable: the same seed and size always give the same maze. A breadth-first search then picks the cell farthest from the start as the exit.

Raycasting: a 3D view from a 2D grid

The maze is stored as a flat grid of squares that are either open or wall. For every column of the image the game sends one ray from your eye, spread evenly across the field of view. Each ray walks through the grid with the DDA (digital differential analyser) method: it compares the distance to the next vertical grid line with the distance to the next horizontal one and jumps to the nearer, so it visits every square it crosses, in order. At the first wall it stops, and that column gets a vertical strip of wall:

strip height = (W / 2) / tan(FOV / 2) ÷ d⊥

W is the image width in pixels and d⊥ the perpendicular distance to the wall, so a wall twice as far away is drawn half as tall. Each strip is textured with a pattern drawn by code and darkened with distance, and walls facing north or south are a little darker so corners stand out.

Why perpendicular distance

Rays near the edge of the view travel farther than the central ray to reach the same flat wall, so their straight length would make the wall bulge like a fish-eye lens. The perpendicular distance, d⊥ = d · cos α, where α is the angle between the ray and your viewing direction, measures distance along the direction you face, as a flat screen does, so straight walls stay straight.

Tips

Frequently asked questions

Is every maze solvable?

Yes. A spanning tree connects every cell, and before each level starts the game simulates a player collecting keys and opening doors to check that the exit can be reached.

Why does Esc pause the game?

Esc releases the captured mouse, so the game pauses. Click Resume (the mouse is captured again straight away) or press P or Esc.

What if the mouse stops turning at the screen edge?

Some browsers do not capture the mouse or stop it at the screen edge. Keep pushing it to the left or right edge and the view keeps turning, up to 150° a second.

Does it work on a phone?

Yes. The view and its buttons fit on one screen, and dragging on the view does not scroll the page.

More free games