Tanks Mayhem is back: 16 years later, in the browser

iamflimflam11 pts0 comments

Tanks! Mayhem is back: 16 years later, in your browser | atomic14

🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board!<br>Get it on Crowd Supply →

Tanks! Mayhem is back: 16 years later, in your browser

View All Posts

read

Want to keep up to date with the latest posts and videos? Subscribe to the newsletter

Posts ·<br>Videos ·<br>ESP32 ·<br>Tools ·<br>Support

« Any Google Font on Your ESP32 Display

HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Back in 2010 I wrote a tank game. It started life as a competition entry to win a laptop from HP by writing something for the Palm Pre (remember those?), got ported to the iPhone and iPad, and ended up on the App Store as Tanks! Mayhem, a Battlezone-style shooter with glowing vector graphics. It didn’t fly off the shelves; even back then competition was stiff in the app world. But it didn’t do badly.

Then in 2011 I got an email from Apple: Atari had complained that a game where you drive a tank around shooting other tanks infringed their copyright. I briefly thought about fighting this, but when your opposition is a company with lawyers on the payroll, it’s just not worth it. I pulled it from the US store, and that was that. I was pretty grumpy about it at the time.

Eventually, I moved on from writing my own apps and the source code has been sitting in a Dropbox folder ever since.

Sixteen years is a long time and things have moved on around it. It no longer compiles and there’s little point in submitting it to an even more crowded app store. It’s 20,000 lines of C++ and Objective-C, OpenGL ES renderers for three platforms, Blender models, sound effects: it’s a lot of code.

So, this week I pointed Claude Code at that folder and asked it to get the game running on the web. 20-30 minutes later:

Play it now at tanks.atomic14.com. Q/A and P/L drive the left and right tracks like the original Mac version, or just use the arrow keys. Space fires. It works on phones too (the original virtual joystick came along for the ride), and if you plug in a gamepad, the two analog sticks map onto the two tracks, which is how a Battlezone-style tank was always meant to be driven.

And here’s the 2010 original for comparison:

How the port worked

I was expecting to get some facsimili to my original game. Maybe a rough clone of Battlezone. Or, a completely broken version of my 16 year old code that barely worked.

Instead, Claude launched a bunch of angents to investigate the code - the renderer, the game logic, the input handling, the enemy tank “AI” etc.. And then it got on with writing the code.

The port over is pretty faithful. The physics runs on planck.js (a JavaScript port of Box2D) with the same damping, restitution and impulse constants as the iPhone version. The models are the original .obj files. The sounds are the original WAVs. It’s an exact port. Pretty impressive!

Recreating the glowing lines

The part about the game that I was really happy about when I wrote it was the nice neon glow effect. I had completely forgotten how it worked but I did remember that I’d done something clever with shaders and linewidths. The models are drawn twice. The dark, nearly-black solid faces go down first (so wireframes occlude properly, with a polygon offset pushing them back), then the edges go on top as 8-pixel-wide GL lines with additive blending. The line fragment shader computes each pixel’s distance from the line’s centre and fades the colour channels. The centre of the line saturates to white-hot, the fringes stay coloured.

Claude rewrote that by expanding each line into a quad. I can’t tell the difference.

Weird bugs in my original code

The initial run that it tested for itself using the Chrome plugin didn’t work - it was just a huge drak polyhedron filling the screen. This turned out to be the player’s tank. Viewed from the indside.

This is Claude’s explanation


My old esRotate function builds a left-handed rotation matrix, and the renderer negates the angle before calling it, so the two wrongs net out to a standard right-handed rotation. The port negated the angle and used a proper rotation matrix, which left a single wrong with nothing to cancel it: every model in the game faced backwards, and the first-person camera stared straight into the back of its own turret. That’s the trouble with old code: the bugs come in pairs that cancel each other out, and fixing just one of them breaks everything.

Some code that shipped 16 years later

My favourite discovery: the source contains a complete, working procedural radar shader (concentric range rings, crosshair, glowing blips, all computed in the fragment shader) that was compiled by the original game and then never called. The shipped game drew the radar with a texture instead. I have no memory of writing it or why I abandoned it.

It’s in the web version now. If you look at the radar at the bottom of the screen, you’re looking at a shader getting its first...

game code original back tanks from

Related Articles