← All stories
1999

Space War: how two little ships taught me trigonometry

In the 1990s there was a hugely popular little game: two ships flying around the screen and shooting at each other. You couldn’t fire a second bullet while the first one was still on screen, and one hit won the round.

In 1998 I got my hands on its source code — gong.pas — and studying it taught me a lot. The biggest mystery for me was vector graphics: how can a ship rotate around its own axis by any angle? I worked out sine and cosine on my own, and found the golden rule:

x = cos(angle) * R
y = sin(angle) * R

I also learned to read the keyboard directly through hardware ports.

Then I made my own version, Space War. It had:

  • ships that deform on ramming, like the cars in Carmageddon;
  • sparks on collisions, a smoke trail, sounds;
  • a vector ship editor;
  • many weapons — bullets of different strength, rockets, homing missiles, bombs, fireworks and a laser that costs points;
  • paratroopers falling from the sky that you could shoot for points, and stars with ammo or repairs;
  • missions, or a free match with any ship against any opponent;
  • my own BMP and WAV loaders, with graphics through the SVGA256 BGI driver.

For a long time I thought the sources were lost forever. Then I found the last versions, up to December 1999 — I was apparently polishing it for a contest. That autumn I started 10th grade, and Space War was the game everyone around me already liked.

1999 was a year of many attempts at a “big game”; several failed. Space War was the first good one.