New to Spectrum Arcade: Reef Raid
Our new 48K and 128K game moves missile defence under the sea: three giant clams burst sinking mines with bubbles. Here's how we made it.
There's a new cabinet in the Spectrum Arcade, and it's under the sea. Reef Raid is a missile-defence game for the ZX Spectrum 48K and 128K, and it's out now. You can play it in your browser in Specz, our emulator, or load the tape on a real Spectrum. Rusty sea mines sink towards six coral reef towns, trailing bubbles as they go. You aim a reticle, press fire, and the nearest of three giant clams on the seabed blows a bubble that rises to the spot and bursts. Anything caught in the burst is popped.
It runs on both machines. On a 48K you get beeper sound effects. On a 128K the AY sound chip adds a sea shanty on the title screen and a tune that climbs in key and pace with every wave. Below, we explain where the idea came from, the choices we made, how we built and tested it, and how to keep your towns standing. To start, press Play on the cabinet, or open it straight in Specz at spectrumarcade.com/arcade/play.html#reef.
The idea
Our earlier games cover flap-to-fly, shooting, bat and ball, cave flying, a text adventure, a platformer, a castle explorer, noughts and crosses, a maze chase, a digging game and a falling-block puzzle. One classic arcade shape was missing: the game where you don't move at all, and instead defend a row of towns from things falling out of the sky.
The best-known game of this kind is Missile Command, designed by Dave Theurer and released by Atari in arcades in 1980. In it, you use a trackball to defend six cities from incoming missiles, firing your own from three bases. Reef Raid borrows that shape: six things to protect, three places to fire from, and shots that explode where you aim rather than where they hit. Its name, its clams, its towns, its creatures, its artwork and its music are all our own.
We moved the whole thing under the sea, and it suited the idea better than we expected. Missiles falling from the sky become mines sinking through the water, and their trails become strings of bubbles. The counter-shot becomes a bubble that rises and bursts. The bases become giant clams, which close up when a mine lands on them.
Designing it
Before writing any code we asked a short set of questions, and the answers shaped everything else.
- Machines. Both. The game fits easily in a 48K, and the 128K adds music.
- Controls. The same standard as our other recent games: Q, A, O and P to aim plus Space to fire, which you can redefine, the cursor keys and a Kempston joystick.
- Difficulty. Classic arcade. The mines sink faster each wave, more of them come at once, and new kinds of attacker join in.
- Sound. Beeper effects on both machines, with AY music on the 128K.
- Extras. A loading screen, a high score kept between games, an attract demo and a redefine keys option.
One big choice was what the fire button does. The arcade game has a button for each base. A Spectrum player has one fire button, and a phone player has one big red one, so Reef Raid picks for you: the nearest clam that still has bubbles sends one up. The middle clam's bubbles rise almost twice as fast as the side clams', which gives you a reason to steer close calls towards the centre.
The other choice was how the waves get harder. The first waves are slow and plain: twelve mines in wave 1, no more than four at a time. Then the extras arrive.
| From wave | What's new |
|---|---|
| 2 | Anglerfish swim across and drop mines from their lures |
| 3 | Splitting mines break into three part of the way down |
| 5 | Urchins sink without a trail and sidestep bursts that land beside them |
| 12 | The table tops out, and the mines keep getting faster every wave |
Each wave also has a score multiplier, from one in the first two waves up to six from wave 11, so surviving longer is worth far more than racing through the early waves.
Building it for the Spectrum
Reef Raid is written in Z80 assembly and assembled with sjasmplus. The whole game, with its graphics, music and demo, is about 10.9 KB, and the tape is 18 KB with the loading screen. It uses no Sinclair ROM routines and draws its text in its own bold font. That's what lets the arcade start it at once in Specz, without loading through the ROM.
The trick at its heart is that everything that moves is drawn with XOR. Instead of setting pixels, XOR flips them: draw something once and it appears, draw it again in the same place and it vanishes, leaving whatever was underneath. Mine trails, the mines themselves, the reticle, the rising bubbles, the bursts and the anglerfish are all drawn this way. So is a town when it falls: we flip the difference between the standing house and the rubble. So the drawing order never matters, and nothing needs saving underneath. The one cost is that where two bursts overlap, the overlap cancels out into a crescent.
The trails show how far that idea goes. A mine remembers where it started and how many frames it has been sinking. When it is popped, the game walks the same path again from the surface with exactly the same steps, flipping the same pixels back off. You see the trail dissolve from the top down.
The bursts were the slowest part of the first version. A burst is a filled disc that grows a pixel at a time, so each step only needs the ring of pixels between the old size and the new one. Working that ring out row by row slowed the busiest waves to about four-fifths of full speed. Now a small Python script works out every ring in advance, as a list of pixel positions for one quarter of the circle, and the game mirrors each list four ways. Pre-shifted sprites and a short list of the bursts on screen helped too. The busiest late waves now run at 92 to 97 per cent of full speed.
Colour on the Spectrum is stored per 8 by 8 character cell, so a single cell can only show one ink colour. That's attribute clash. Reef Raid keeps all its moving things in white ink on blue water, so they never clash with each other. Bursts colour the cells they cover in flashing white, yellow and cyan, or red and yellow when a mine hits the seabed, and a copy of every cell's proper colour puts them back afterwards.
All the graphics start as ASCII art in a Python script, with a hash for ink and a dot for paper: the font, the mines, the urchin, the anglerfish, two styles of shell house, the rubble, the clam open and shut, and the sand. The same script draws the loading screen, with the title in big coral letters, sinking mines and a big open clam with its pearl. The AY music is original too: a shanty called Kelp Shanty on the title, and an in-game tune that moves up a key and speeds up as the waves go by.
Testing it like a player
Every build was tested by loading the tape through the real 48K and 128K Spectrum loaders in Specz, as well as by the arcade's quick start. A computer player then played it. Each frame it reads the game's list of mines, picks the one that will reach the seabed first and isn't already covered by a bubble or a burst, and aims ahead of it, allowing for the time the reticle takes to get there and the bubble takes to rise.
That player turned out to be a good judge of fairness. In the first version it ran out of bubbles from wave 7 and lost the reef by wave 10, however well it aimed. There were two reasons.
- Urchins that couldn't be caught. They sidestepped at one and a half pixels a frame, but a burst only grows at one pixel a frame, so even a burst right on top of an urchin let it escape. They now sidestep at three-quarters of a pixel, so a direct hit always works and only a near miss lets them slip away.
- More mines than bubbles. By wave 10 a wave held more mines, urchins and anglerfish than the three clams' 30 bubbles could answer one for one. We lowered the counts and let the difficulty come from speed and from how many sink at once.
After those changes, across ten different games the computer player lost its first town somewhere between waves 6 and 11, and the reef fell between waves 11 and 18. That feels right for a classic arcade game. The test also found real bugs.
- A counter in the wrong place. When a mine hit a clam, the game passed the clam's old bubble count to the routine that draws its counter, instead of the clam's number. The counter appeared far off to one side and scribbled into the score line. The test now checks, every frame, that nothing touches the score line or the sand.
- Urchins in the score line. Urchins are taller than mines but started at the same depth, so their spikes poked into the top row. They now start a little lower.
What we couldn't check is how the sound effects and music sound through a real Spectrum's speaker and AY chip, or how aiming feels on a real rubber keyboard. If you try it on real hardware, we'd love to hear how it goes.
How to play
Move the reticle with Q, A, O and P, the cursor keys, a Kempston joystick or the on-screen pad, and press Space or fire. The reticle speeds up the longer you hold a direction. A small cross marks where your bubble will burst. ENTER pauses, and R on the title lets you pick your own keys.
Each clam holds ten bubbles a wave. A mine that reaches the seabed bursts on the town or clam it was aimed at. A town falls to rubble, and a clam snaps shut and loses the bubbles it had left, though it's back next wave. When every town has fallen and you have no bonus town to rebuild one, the reef has fallen and the game is over.
| Target | Points |
|---|---|
| Sea mine | 25 |
| Anglerfish | 100 |
| Urchin | 125 |
| Each bubble left at the end of a wave | 5 |
| Each town still standing | 100 |
All of these are multiplied by the wave's multiplier, and every 10,000 points earns a bonus town that rebuilds a fallen one at the start of the next wave. Your best score is kept, and the arcade saves it in your browser.
- Aim ahead. Mines keep sinking while your bubble rises, so put the reticle a little below and in front of them.
- Catch two at once. A burst is wide. When two trails come close together, one bubble can pop both.
- Pop splitters high. Once a splitting mine sinks far enough it sends two more off at other targets.
- Land right on the urchins. They dodge bursts beside them, but not one on top of them.
- Keep the middle clam for emergencies. Its fast bubbles are best for mines that are nearly down.
Play it now
Reef Raid is in the Spectrum Arcade now. Press Play on its cabinet, or read the full guide on its game page. If you have a 128K, or let Specz start as one, you'll get the shanty. To see how our other recent games came together, read how we made Present Tense or how we made Skullslide. And if the Spectrum itself is new to you, our history of the ZX Spectrum is the place to start.