ALFTANET
← All guides

Drawing a cave with 27 colours

Rockfall is my tribute to the 1984 cave-digging games. Every colour on screen is one an Amstrad CPC could show, and every cave goes through a checker before it ships.

I first built Rockfall on 23 August 2026 and rebuilt its look on 14 September. It is a cave-digging puzzle in the tradition of Boulder Dash (First Star Software, 1984) and its home-computer conversions. The rules of the genre are borrowed openly. Every cave, sprite and creature, the pixel font and every sound are new.

Dirt holds the rocks up

You tunnel through soil collecting gems. Boulders fall into the gaps you make, roll off the round tops of other boulders, and crush whatever is under them, including you. A falling boulder kills; a resting one never does. That rule gives you exactly one step of warning. Collect the cave's quota of gems and the exit opens. Then get out before the clock runs down.

Rockfall cave A: a miner in the top-left corner of orange soil with grey boulders, cyan gems and a red brick wall, under a status bar reading 00/12 gems, 149 seconds and 3 lives
Cave A as it opens: twelve gems to find, 149 on the clock, three lives. Soil, brick and stone colours change from cave to cave.

Twenty-seven colours

The Amstrad CPC could show 27 colours: each of red, green and blue either off, half or full. Rockfall uses only those. The test reads back every pixel of every cave and fails the build if one isn't on that list. Each cave has its own soil, brick and stone colours. Their shade and highlight come from stepping each channel one level down or up, so the derived colours are ones the machine could show too.

Wide pixels

The CPC's 16-colour mode had pixels twice as wide as they were tall, and the Commodore 64's multicolour mode worked the same way. Rockfall draws each tile as an 8 × 16 grid of those wide pixels, each one 4 × 2 screen pixels, on a black screen. Things move a whole tile per step, every 110 milliseconds, with no smooth in-between, as they did in the originals. The camera stays still while you work and scrolls when you get near the edge. The status bar uses my own 5 × 7 pixel font.

Caves nobody edits by hand

A run has twenty caves, A to T, and a one-screen bonus cave after every fourth: the shape of the original. A bonus cave costs no life if you fail it and gives one if you clear it. The caves are stored as text grids inside the game, and a Python tool writes them there. Nobody edits them by hand.

The first twelve were drawn by hand for the first release. They now get a seeded scatter of stone and gems, only into plain soil and never next to a creature, so they read as rock rather than graph paper. The rest are built the way the originals' own cave format worked: a seeded random fill of the whole cave, then lines and boxes drawn over it. Two passes keep the random fill honest. One pins anything that would fall or roll the moment the cave opens. The other opens the stone around any gem the dice sealed in completely.

A contact sheet of all 25 Rockfall caves: twenty large caves in four columns, each in its own colours, and five small bonus caves in a column on the right
All 25 caves on one sheet, as the test draws them: the twenty main caves, 40 × 22 tiles each, and the five bonus caves on the right.

The checker

Before it writes anything, the tool checks every cave: its size, that only CPC colours are used, that every creature starts next to something that stays put, and that nothing is already falling onto the start. Then it flood-fills from the player's start to prove that every gem and the exit are on the player's side of the steel walls. If one cave fails, it writes nothing.

It also catches things I didn't think to look for at first. Grey soil can hide grey steel, so that pairing is now checked. Expanding walls grow one tile a step into any empty space beside them. They turned out to be a hazard in a few places and a cage everywhere else: nine pillars of it once sealed a whole cave.

A bot that sees everything

The test also plays every cave with a bot that has perfect information. It avoids what a careful player avoids: stone poised over a tile, stone about to roll into one, digging beside an expanding wall. Where the loose gems cover the quota with half again to spare, the bot must clear the cave or the build fails. If a bot that sees everything can't clear a cave, the cave is at fault, not the player.

The bot had bugs of its own first. Five of the first six caves that "failed" were the bot's fault. It couldn't grab, it couldn't push, it changed its goal every step and paced back and forth for 4,000 steps, it replayed the same death every life, and it reported the gems from its last life instead of its best.

The bot also measures how many points a second a good run earns. The server's limit on believable scores comes from that number, and the test fails if the margin is under 1.5 times or over 60.

The rules I kept

Fireflies follow walls and try to turn left first. Butterflies try right first, and one crushed by a boulder bursts into nine gems. The amoeba grows into air and soil; sealed in, it turns to gems, and past its size limit it turns to stone. A magic wall turns falling boulders into gems for a while. Pushing a boulder takes two shoves. All of that belongs to the genre, and all of it is drawn and coded from scratch.

Airshaft does the same for the Manic Miner style of platformer, with a 256 × 192 screen of 8 × 8 cells. For a generator that checks its own work as it goes, see how Redline keeps its tunnel fair.