AppStars

Online high scores in 2000: a shoot-'em-up in a Java applet

Where our engineering story starts: a browser shoot-'em-up from November 2000, with levels stored as pixels, frame-time movement and a Perl high-score table.

In November 2000, if you wanted a game to run on anyone's computer without an install, you had one real option: a Java applet in a web page. The browser gave you a small rectangle, an AWT graphics context, a few .au sound clips and whatever speed the visitor's PC happened to have. We wanted a full vertical shoot-'em-up in that rectangle, with online high scores, years before app stores had leaderboards.

The game was called The Void. It's the oldest web code in our archive, and a surprising amount of what we still do started in its 3,688 lines of Java.

The problem

Browsers in 2000 were not game platforms. The constraints were blunt:

  • No guaranteed speed. The same applet ran on a fast desktop and on a tired school PC. A game that moved one pixel per frame would be twice as fast on one as the other.
  • Flicker. Drawing straight to the screen with AWT showed every half-finished frame.
  • Downloads were slow. Every image and sound came over a dial-up modem, so the fewer files, the better.
  • No server to speak of. Shared web hosting gave you a cgi-bin folder and Perl. That was the whole back end.

The year before, we'd written Carbie, a DirectDraw platformer for Windows with levels loaded from text files. The Void took the same idea, data-driven levels and a fixed loop, and moved it into the browser.

Architecture

The applet was small and split by job:

  • Void, the applet itself: keyboard input, the player, the score and a blit thread that repainted the screen.
  • Enemy, which ran on its own thread, read the level and owned the lists of enemies, bullets, explosions and power-ups.
  • Collision, typed rectangle tests between the player, bullets and each kind of enemy.
  • Two Perl CGI scripts on the web host, which kept the high-score table.
 keyboard -> Void applet ---- blit thread ----> offscreen image -> screen
                 |
                 +-- Enemy thread: level image -> spawn Basic / Jet / Appache
                 |                 / BoatBaddie / EndBaddie, bullets, power-ups
                 |                 -> Collision
                 |
                 +-- game over -> highscore.cgi (Perl) -> highscore.dat

All drawing went to an offscreen image first, then to the screen in one step. That's double-buffering, and it removed the flicker. Every sprite lived in a single sprite strip image, and each draw set a clip rectangle on the offscreen buffer so only the right frame of the strip showed. One image download instead of dozens.

The engineering

Levels stored as pixels

The level wasn't a file format. It was a GIF. We painted the level as a small image and read it back pixel by pixel with AWT's PixelGrabber. As the screen scrolled, the enemy thread looked at the pixel for the current position: the red channel said which enemy to spawn and the green channel said where.

tempcol = ( currentLevel[levelpos]   >> 16) & 0xff; // red: enemy type
tempx   = ( currentLevel[levelpos+1] >>  8) & 0xff; // green: x position
if ( tempcol != 0 )
{
    switch (tempcol)
    {
    case 210: vEnemy4.addElement ( new BoatBaddie (tempx) ); break;
    case 230: vEnemy2.addElement ( new Jet ( tempx, tempy) ); break;
    case 240: vEnemy1.addElement ( new Basic( tempx, tempy) ); break;
    case 250: vEnemy5.addElement ( new Appache () ); break;
    }
}

It was a level editor for free. Any paint program could design a wave, the image compressed well, and it came down in the same request as the art. The same instinct, letting people author content in a tool they already know, shows up in nearly every tool we've built since.

Movement scaled by frame time

To make the game play the same on fast and slow machines, the main loop measured how long the last frame took and scaled movement by it:

endLoop  = new Date();
timeLoop = endLoop.getTime() - startLoop.getTime();
PlayerVel = timeLoop*0.2f;

Enemies took the same timeLoop as their velocity. A slow PC drew fewer frames, but the ships covered the same distance per second. Today every game engine hands you a "delta time"; in 2000 in an applet, you measured it yourself.

Cheap, forgiving collision

Collision used rectangles, but not the sprite's full rectangle. Each type got a hit-box worked out with two shifts and a subtract:

width1  = (PlayerWidth>>1) - (PlayerWidth>>3);
height1 = (PlayerHeight>>1) - (PlayerHeight>>3);

Half the width minus an eighth gives a half-extent of three-eighths, so the box is three-quarters of the sprite. Integer shifts were cheap on any CPU, and the smaller box meant a bullet that clipped a wing tip didn't kill you. Players feel that as fairness, not as maths. The same shift-and-add habit carried straight into our Game Boy Advance engine, where it mattered far more.

High scores before leaderboards

When a game ended, the player's name and score went to highscore.cgi, a short Perl script on the web host. It read a flat file holding the top 50 names and scores, found where the new score belonged, shifted everything below it down one place and wrote the file back out.

That was the whole leaderboard: a text file and a CGI script. It worked. In 2000, under the Halfbrick name, we offered games like this to website owners as a way to keep visitors on their site, with prizes and incentives based on the scores people posted.

Where AI fits

There was no AI in the modern sense. There was game AI in its simplest form. Most enemies flew fixed patterns, but the boats fired a "smart" bullet: when it was fired, it took the player's position and set off towards it.

It aimed once. It didn't track you. That was a deliberate, cheap trick: a bullet that steers every frame is expensive and feels unfair, while one that aims at where you were rewards moving. A little intelligence, placed carefully, made the game feel alive.

It's the first rung of a ladder this series climbs: from scripted enemies to state machines and path-finding in Game AI before "AI", and on to machine learning, computer vision and the models we run on devices today.

What it taught us

Looking back at this code with today's eyes, two lessons stand out, and both were learned the hard way.

Never trust the client. The score that reached the server was whatever the browser sent. Anyone who looked at the request could post any score they liked. Today a leaderboard, a payment or a form submission gets validated on the server, rate-limited and tied to something the client can't forge.

Shared state needs a lock. The Perl script read the whole table, changed it and wrote it back, with no locking. Two people finishing at the same moment could overwrite each other's entry. It never mattered at that scale, but it's the same read-modify-write race that causes lost updates in modern systems. It's why we now use database transactions and version checks on every write, as in our post on offline-first sync.

There's also a note at the top of the enemy code, in capitals: remember to stop this thread when a new level starts or the player dies. Thread lifecycles were already the hard part. They still are.

Why it still matters

The Void was a small game, but the constraints were real ones: unknown hardware, slow networks, a thin server and players who notice when something feels unfair. Those are still the constraints of most web and mobile products. We design for the slowest device, keep downloads small, keep authority on the server and make sure two people saving at once can't lose each other's work. If that's the kind of care your platform needs, see our web and SaaS platforms work, or read on to real-time 3D on a 16 MHz handheld, where the same habits met much tighter hardware.

Bring us the hard problem.

A 45-minute discovery call with the engineer who'll build it.