Mutant killer, Mario and more: rediscovering old projects

I was reorganizing some folders on my laptop and ran across some really old code I'd written. I knew the code was there, but I hadn't looked at it in years and thought it would be fun to take a peek, so I created a WindowsXP virtual machine and fiddled around trying to get the various programs to run.

Games

I was surprised to find three different versions of Pong. The best-looking and most playable one was written in C++. At the top of the source file is the following comment:

// IMPOSSIBLE PONG BY CHARLIE

I did some "back of the napkin" calculations using the maximum velocity values in the game, and in fact it is impossible to beat the computer. Here's a screenshot of the game board:

p1404140674.04.png

The entire game code is pretty hideous. For some reason I refused to use const and just hard-coded magic integer values all over the place. I guess I never expected to want to play at anything larger than 640x480 resolution. Below is the logic to move the computer's paddle. If the ball is moving away from the computer, the paddle will be roughly centered on the screen, otherwise, it will move to the expected point-of-contact for a perfect "return":

//Computer AI
if (ballvx < 0) { // ball moving away from computer, move to center.
  if(cpy > 260) cpy -= 8;
  if(cpy < 200) cpy += 8;
} else if (ballvx > 0) {
  // How long will it take for the ball to reach cpu side?
  simvx = ballvx;
  simvy = ballvy;
  simx = ballx;
  simy = bally;
  a = (632 - simx) / simvx;
  // Now, find out what the Y coord will be at that time
  for(index=1; index<=a; index++) {
    simx += simvx;
    simy += simvy;
    if (simy + 4 >= 449) simvy = -simvy;
    if (simy <= 1) simvy =-simvy;
  }
  if (cpy+20 < simy) cpy+=8;
  if (cpy+20 > simy) cpy-=8;
  if (cpy>=410) cpy=410;
  if (cpy<=2) cpy=2;
}

One of the Visual Basic pongs was eerily similar, so I guess I must have just ported one version to the other:

Dim simvx%, simvy%, simx%, simy%
Dim a%, Index%
simvx% = vX%
simvy% = vY%
simx% = bX%
simy% = bY%
a% = (620 - simx%) / simvx%
For Index% = 1 To a%
    simx% = simx% + simvx%
    simy% = simy% + simvy%
    If (simy% >= 440) Then simvy% = simvy% * -1
    If (simy% <= 30) Then simvy% = simvy% * -1
Next Index%
If (cy% + 17 < simy%) Then cy% = cy% + 5
If (cy% + 17 > simy%) Then cy% = cy% - 5
If (cy% >= 415) Then cy% = 415
If (cy% <= 0) Then cy% = 30

Just look at all those percent signs and magic numbers!

Around the same time I also wrote a version of the Nokia Snake game that my friends and I played on our cell phones. I've got a javascript version which you can play on my site, but the Visual Basic version looks much better. And yes, I believe I used Comic Sans for the scoreboard:

p1404697291.64.png

Existential

I found another partially-completed game called Stickman that shows an animated stick-figure walking across a desolate landscape, devoid of any scenery. The stick man can walk to the left or right, jump, or, by pressing spacebar, commit suicide. The death animation shows him exploding in a cloud of blood.

After he dies, you can press enter to restart. But then, why would you?

photos/s1404012758.17.png

Killing mutants

The first real platformer I wrote was called Mutant Killer. I just assumed the code was long gone so it was a real surprise to find everything still intact. The premise is that you are a guy with a shotgun and you jump through a level blasting mutants. Here is the art I made for splash screen:

p1404697347.1.png

The actual game-play looks like this:

p1404697480.69.png

To build the levels (I think there are 6 of them) I made a level editor. You click the tiles on the right-side and "paint" them onto the game screen. I think I drew all the tiles myself. There are also some special tiles, for instance the cross will kill all the mutants on the screen, and the weird face will send you back to the beginning of the level.

p1404697492.92.png

I wouldn't say Mutant Killer is very fun to play, but it doesn't seem to have many bugs and the collision detection is at least implemented correctly!

Mario

Fast-forward in time 6 or 7 years. I was working as a court reporter after college and for fun I had installed Visual Basic on my laptop. I decided it would be fun to try and write a Mario clone. Once I got started, I found myself working on the game during breaks in work, at night and on the weekends. The joy I experienced working on this game convinced me to quit my crappy job and pursue a career as a programmer.

The first level begins with an homage to the original:

p1404698230.25.png

The levels become increasingly difficult, and also increasingly abstract.

p1404703476.88.png

I added a number of new tiles, as well as tiles and enemies from the super nintendo version of mario (the bird in the corner).

p1404698240.51.png

I also made it so that when you stomped on a goomba or other non-shelled critter it would leave a gory pile of blood and guts:

p1404835275.83.png

Once again, I built a "palette"-style level editor. I spent several hours taking screenshots while playing the original Mario game in a NES emulator, then converting the images into sprites and tiles. This is what the level editor looks like, and you can see that, in addition to the normal mario tiles, there are some new ones (and some new monsters):

p1404698392.22.png

p1404698553.59.png

I had so much fun writing this game! If you'd like to try it out, you can download it here -- runs best on Windows XP. Also, I don't know if the full-screen mode is working correctly, so your best bet is to choose 640x480 in the startup screen.

Tetris and Galaga

After finishing up Mario, I decided to try my hand at writing a few games in C#. At this time I was frantically trying to land a full-time job as a programmer and I figured if I could point to one or two games I'd written in C# it would help out my resume.

This was the first time I'd written a Tetris clone, and after working on Mario (which was sprawling and completely insane by the time I called it finished) it was very refreshing to focus on something so pure and simple. Despite this I managed to make a big mess of the code, but the principles at work were at least simple.

I'm still a little bit in love with the splash screen I came up with for Tetris. I was trying to make it look old-school but kind of minimalistic as well:

p1404698873.71.png

The gameplay screen is a little hokey with the curved panels around the text and everything, but I like the way the boxes look:

p1404698882.94.png

I've got a javascript version you can play on my site. If you'd like to try the C# version, you can download it here.

After finishing up Tetris I decided I would try to code up Galaga. I was playing in a pool league at the time and the pool hall had a Galaga game near the restrooms. While waiting for my turn on the pool table I would sometimes spend my extra quarters trying to beat the high score, which seemed feasible (I never did end up beating it, though). I really love the gameplay of Galaga, the furious blasting, the neat patterns formed by the aliens, the stars racing by in the background, and the unforgettable intro music...

I called my clone Space Carnage, and though I never finished it, I still had a great time working on it.

The intro screen plays the music and scrolls down the original Galaga logo:

p1404701026.78.png

Once the game begins, the enemies fly in formation onto the screen, performing loops which I had fun coding up using what I could recollect from my Junior High geometry class.

When I began writing Space Carnage I was still trying to find a job, and was doing informational interviews with programmers in the area. On the advice of one of them, I picked up Head First: Design Patterns. So I had an Enemy base-class and some subclasses. I had all the enemies using various FlyBehaviors, and there were lots of other fun object-oriented things going on. This code was a lot more manageable and readable than anything I'd written previously, but since I did not yet have a solid grasp on OOD, I think I fumbled around quite a bit with the question of where one object ends and another begins.

At any rate, it was very fun to write and maybe I'll take the sprites and try to implement it with JavaScript one of these days.

Then it happened

Around the time I had implemented my fifth FlyBehavior in Space Carnage, I got an offer to work for a local web development shop doing PHP/MySQL. I had always been a Windows user and figured that my career would be spent building .exe files, but since this was to be my first job I decided not to be picky and accepted it (and I am so glad I did). I finally got teachers patient enough to teach me the correct way of doing things (Tyler Wilkinson, Eric Holscher, Christian Metts, Matt Croydon, Alex Kritikos, Dave Peticolas -- thanks for your help!). I think the one thing I take away from all that bad code is that the most important aspect of any program is the data-structures. Rob Pike said it better:

Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

And I think Rob Pike was riffing on something Fred Brooks said before:

Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious.

I hope you enjoyed reading this post. As always, please feel free to leave a comment below!

p1404702389.34.JPG

Comments (0)


Commenting has been closed, but please feel free to contact me