Spacewar in Codea Lua

Years ago, I encountered the game Spacewar, originally written for the Type 30 display on the DEC PDP-1 computer. Spacewar was surely one of the first “video games”, since almost no one had the hardware to run such things. Being seriously geeky, I set out in my spare time to write my own version, fit to our hardware, including the somewhat more powerful Type 340 display. That version was written in assembler, right up against the metal. It’s hard to imagine more fun than that. We’ll try to get close here, and maybe to learn a bit too.

Codea, by Simeon, is a very lovely software development system, supporting the Lua language. Lua is a C-like language, very simple, with some very nice design elements, as we’ll see. It’s not as close to the metal as assembler, but it’s close enough to be plenty of fun. Feels like real programming to me.

The plan here is to write a Spacewar, describing what I think about, what I encounter, what really happens. I have in mind something like my Adventures in C#, only not so long and difficult to write. My motto in this kind of thing is “Warts and all”. I mean to show you, not some perfectly polished ideal program, but a real program, written by a real person who misunderstands things and makes mistakes. I will try to end up with a program one can be proud of, so that we’ll see how that can happen even though I’m far from perfect.

For more on Spacewar itself, I’d suggest these links: Spacewar and Computer History. There’s a demo, quite realistic if my recollections are good, at Masswerk.

I won’t be trying to emulate the hardware, nor even to copy the style of the original program exactly. I will be building a very “close to the metal” version, and I’ll be starting as simply as possible, probably with a dot in the middle of the screen. I plan to code very experimentally. I’ll work from very simple, almost stupid code. I’ll make very incremental changes. I’ll try never to build something because “we’re going to need it”. I’ll be doing these things to see what happens. Do I get trapped in a box because of my “legacy” code, or can I always spot the concern and refactor my way out of the problem?

And what about testing, in particular TDD? When you’re moving pixels around on the screen, what kind of testing is called for? When you’re working in a system like Codea/Lua, what kinds of things go wrong, and what kind of testing might have prevented them?

How will it go? We’ll see. I expect to find it interesting, and hope that you do as well. Welcome!