Posts from Thursday, September 25th, 2014

Gravity Wars Redux

Published 9 years, 6 months past

Over the past few weeks, I’ve been writing a remake of/homage to a game I last played somewhere around 1990: Gravity Wars.  I gave this personal project a few hours here and there each day, or more usually each evening, slowly resurrecting a little piece of my past and putting my own spin on it.  You can check it out for yourself, if you like: Gravity Wars Redux.

There are a few things I changed from the version I played all those years ago, besides the change of colors.  First of all, instead of taking turns, in my version the ships fire simultaneously, meaning a no-survivors tie is possible.  Second, the shot preview paths weren’t part of the original game.  Third, the “Gravimetric display” wasn’t a thing in the original game either.  That and the shot previews are leftovers from my development testing that I decided to keep around, either because I thought they added something to the game or because I just liked them too much to dump.

In fact, most of the code in there is accreted leftovers from the experimentation and development process.  Looking at it now, I can see all the things I should have done.  It just got to a point, as with most coding projects, where I could add another scoop or two of spaghetti to the existing mound and ship it, or I could start over and try to make the lasagna properly this time.  I decided to ship it.

I have to admit the point of all this wasn’t actually to recreate Gravity Wars, as much as I like the game and am glad to have a working copy of it.  It was instead to teach myself about the canvas API, and also to try to get a handle on some JS features that have never quite made sense to me.  I think I did okay on the both fronts, in my own idiosyncratic way.

At this point in a JS-related post, I usually throw in a disclaimer about being a JS newb whose code should never be inspected by anybody.  That’s probably still true, but I know I’ve advanced quite a bit from where I was, which pleases me.  I can see that not just in that the code I’m publishing today, which is convoluted and clumsy but still better than what I’ve written in the past.  I can also tell I’ve gotten better simply because I can see better approaches, as a result of what I learned along the way.

This may be where I end the project, or I may go back and take another crack at making lasagna.  We’ll see.  The carrot for me in doing that is it would let me add some other fun features and useful improvements pretty cheaply, not to mention I could fix some things that aren’t quite what they should be (like the placement of planets and ships, which should be a little less random).  The stick is of course having to rewrite code I already wrote.  I mean, lasagna is nice and all, but I like spaghetti too.

Anyway, I enjoyed writing it and learning as I coded, so if slinging missiles around planetary limbs sounds like your idea of a good time, please enjoy.


I’m indebted to Sohrab Ismail-Beigi, whose 1989 PASCAL source code I studied and in some cases directly ported; and to pascal-source.ru, for making that code available for download.  My thanks to both.


Browse the Archive