Porting (and emscripten’ing) some legacy code (>20 years old)


I have an old post (http://www.neilbirkbeck.com/?p=1066) that discussed some of the first Game clones that I had made when I was first starting to code (sometime in the early 2000s). At the time, I was using windows and must have been using some online tutorials for how to do DirectX Graphics.

A few weeks ago, I was interested in checking out some of that code to see how much effort it would be to port it over to Linux. In the back of my mind, I was also thinking it would be cool to get things running in the brower (using Emscripten). So when deciding which libraries to use for Linux, I wanted to make sure that I chose ones that would be compatible with Emscripten — if possible. Turns out SDL was supported.

Overall, the limited subset of DirectX that I was using very close to the APIs offered in SDL. So porting the first game (bomberman) was fairly easy and maybe only took a few hours of work for the first game. And since my “engine” was fairly similar, finishing the other games (which were made earlier) was fairly easy.

The code for the various projects is horrendous (it is over 20 years old now), and basically I had no idea what I was doing.

Projects

Bomberman

The first of the games that I ported over was Bomberman. There were some features that I didn’t bother with (e.g., there is also a music player that was using FMod Sound).

Bomberman even had some very primitive AI.

Bomberman even had a crude version of multiplayer. I remember at the time, I was heavily influenced by Quake 3. So I had a console where you could connect to a server. Unfortunately, there was no real synchronization between the game state — only the action was sent from client to server (and vice versa) so it was possible for the client and server to get out of sync. An example of what it looks like in the following video:

Once I had the Linux code working, it was surprisingly easy to get things working with Emscripten. The only hiccup was around setting up some library flags and debugging some the sleep function. It was the only thing that needed special handling. The Emscripted version looks like:

You can try it out here:

http://www.neilbirkbeck.com/legacy/emscripten/bman.html

Use ‘a’, ‘s’, ‘d’, and ‘w’ to move. And z/x to place bombs / explode them if you have the detonator.

Breakout

Next up was Breakout. Use the mouse to move the pad and press ‘ ‘ to release the ball. The default level has tonnes of powerups. This one was never completed (e.g., no title screens, etc.). This may have been the very first game…

Again, there is a terminal (press tilde) and there are a few commands (map, to set the level e.g., \map map1.txt, or \give ball.

http://www.neilbirkbeck.com/legacy/emscripten/arkanoid.html

Pacman

For pacman, I remember one of the “innovations” I had added is that you can use the space key to chew through the walls. The wall rendering is done for each frame so it was easily to update.

Pacman demo video

http://www.neilbirkbeck.com/legacy/emscripten/pacman.html

Titris

Last, but not least is titris — a tetris clone. Despite having written various versions of tetris. This was the first one. And was probably the first crack at any AI that I had. At the time, I remember thinking that AI was just a bunch of If/else statements. I basically had no idea what I was doing, but still came up with something that kind of worked. Press ‘p’ to test out the AI:

An example of titris

http://www.neilbirkbeck.com/legacy/emscripten/titris.html

Code

All the code is here. Be ware, I didn’t know what I was doing, and in porting the code to Linux all I did was clang-format (no real fixes).

  1. No comments yet.
(will not be published)

  1. No trackbacks yet.