AYOUB.*[ARCADE]

Boulder Dash

Score0
Cave1
Lives3
Best-

ENGINE SPECIFICATION // ARCHITECTURAL GUIDE

How to play Boulder Dash

Controls for Boulder Dash
KeysAction
← → ↑ ↓Move / dig / push
W A S DMove / dig / push
P / EscPause / retry cave
Space / EnterStart / resume

On phones and tablets, use the on-screen tactile D-pad under the viewport.

About Boulder Dash

Boulder Dash is a cave-digging puzzle game on a grid of 20 by 18 cells. You tunnel through dirt one cell at a time, pick up diamonds and push boulders out of your way. Each cave has an exit door that stays shut until you have collected the number of diamonds shown under the cave. Once it flashes open, step into it to clear the cave and move on to the next one.

Every cave has its own clock, between 50 and 90 seconds depending on how far apart the diamonds are. You start with three lives. Being crushed by a falling boulder or running out of time costs a life and restarts the cave; lose all three and the run is over. Walls can't be dug or pushed.

Scoring, levels and tips

  • Each diamond is worth 10 points, or 20 once the exit is already open. Clearing a cave adds 1 point for every second left on the clock.
  • Caves get harder as you go: more boulders, more diamonds to collect, a tighter clock and faster falling rocks. Cave 1 needs 6 diamonds; from cave 11 on, every cave needs 14.
  • Boulders and diamonds fall straight down into empty space. One resting on another boulder or diamond rolls sideways off it when the cell beside it and the cell below that are both empty.
  • A boulder only hurts you while it is falling. One resting on your head is safe until you move away, so never dig straight down from under a boulder: it follows you down and lands on you. Step sideways instead. A diamond that drops onto you is simply caught.
  • You can push a boulder one cell sideways if the cell beyond it is empty, then step into the space it left. Boulders can't be pushed up or down.
  • Boulder physics run on their own tick: 160 ms per step in cave 1, 6 ms quicker each cave, down to 100 ms.
  • If a rockfall seals you in, pause and choose Retry Cave. It costs a life but saves waiting out the clock.
  • Your best score is saved in your browser.
  • Tip: take diamonds that sit under boulders from the side, not from below.
  • Tip: keep a route to the exit open, or rocks you knock loose may bury it.

How it's built

The game is written from scratch in TypeScript on an HTML canvas, with no game framework. The cave is a 2D array of cell codes (air, dirt, boulder, diamond, wall, door and player) in a simulation module with no canvas or DOM code. Each cave is generated from a fixed seed for its number, so cave 5 is always the same cave. Walls, air pockets, boulders and diamonds are scattered, the physics run until everything has settled, and a breadth-first search then checks that enough diamonds and the exit can be reached from the start without moving a single boulder. A cave that fails the check is rebuilt.

Boulder physics scan the cave from the bottom up once per tick, so a stack of rocks drops together. Every boulder and diamond remembers whether it moved on the last tick, which is how the game tells a falling rock, which crushes you, from a resting one, which doesn't.

The physics keep their own time budget inside a shared fixed 60 Hz loop, while your moves happen instantly on each key press and repeat every 115 ms while a direction is held. Sound is synthesised with the Web Audio API, and on touch screens you can hold the on-screen D-pad, drag across the board or swipe.

This is an unofficial tribute written from scratch for the browser. It is not affiliated with or endorsed by the owners of the original game.