More Mini Projects

I’ve been tinkering with a few mini projects lately, all of which are available from my BitBucket page:


Networked Pacman

Though I released this ages ago, I published it as a zip archive instead of hosting the code in a source code management system. I’ve rectified this and added it to BitBucket:

Networked Pacman


This is a simple implementation of the logic of Scrabble, written in Python 3. It doesn’t have a UI, so it’s not terribly exciting for anyone but Python programmers, but perhaps someone will write a front-end for it. This was written in a couple of days and was an exercise in trying to think “Pythonically”. Whether or not I achieved this I’m not sure…



Finally, this is a C# library that provides date functions that operate on a user-defined working week. For example, you can define a week of 9:30am to 5:30pm shifts (with time for lunch, natch) and use the functions provided by the library to determine whether or not a given date/time falls within a shift, or how many working hours there are between two dates, etc. It does some neat things with custom iterators and the yield statement to condense a lot of fiddly logic into a couple of very powerful methods.



Networked PacMan and Embedding Video

Adding video to a blog not hosted on one of the main blog providers is a real pain. WordPress has about a dozen plugins that handle video, most of which haven’t been updated in a while and are tricky to configure. The worst offenders are the plugins that handle anything other than FLV format videos or streamed videos hosted on sites like YouTube. That’s a shame, because actually creating FLV videos is itself far more work than it should be. A simple plugin that played MOV or AVI files would be greatly appreciated.

I eventually decided upon the FLV Embed plugin. It seems to be reasonably up-to-date and is very easy to use. Unlike the YouTube streaming plugins, it lets me keep the video files hosted on my own server.

Once I’d installed the plugin I needed to get my video into FLV format. This, as previously mentioned, is a huge pain. My version of Flash is PPC-only and I don’t want to have to install Rosetta on my nice clean Snow Leopard install, so using Flash is out. FFmpegX depends on a binary that is also PPC-only (and hasn’t been updated in over a year) so that’s out too. All of the other FLV converters for both the Mac and Windows are either crap shareware applications, look like they contain malware, or both.

(As a side note, why is it that all of these crappy shareware programs insist on creating skinned UIs? They all look like the kind of shovelware that gets installed on new PCs that anyone with any sense uninstalls before they even attempt to use the computer.)

Anyway, the only FLV converter I found that was remotely useful was iVideoConverter. It is a shareware app, but it’s got a good UI and it actually works, which is more than I can say for the rest. As it’s just a front-end for ffmpeg, you’d expect nothing less from it. I nearly resorted to using the HTML5 video tag, but since the browser manufacturers refuse to agree on a video standard, it’s rather pointless. (EDIT: After some testing, it seems that Safari will play Ogg Theora - though that may be because I’ve got all sorts of video players installed, including Perian - whilst Firefox refuses to play anything at all, despite me having configured the appropriate MIME types.)

Anyway, the whole purpose of this waste of a weekend was to post a video of a project I wrote a while ago. I created a networked version of PacMan as part of a five week group project for my master’s degree. The project as it was submitted was rather larger - it had a second game and a database behind it. I’ve stripped out just about everything that I didn’t personally write (barring the XML config file stuff) and the database (simply to make it easier to distribute).

In this version, the first player to connect to the server plays as PacMan; the other players control the ghosts. By default, it supports 2, 4, 6 or 8-player games, but the code itself will support any number of players. Here’s the video of it in action; it shows two networked clients running on the same host:

The game can be downloaded here:


This includes the NetBeans project with full sourcecode, plus Java binaries and instructions on how to run them. Note that in order to play the game you need to have the JVM 1.5 (at least) installed.


Woopsi PacMan

The Pong demo in Woopsi is a bit crap. It served its purpose, but it doesn’t really do anything. I wanted a more interesting demo, but didn’t want to invest a lot of time in writing a new game, so decided that it would be simple to port my PacMan-for-Javascript to C++ and Woopsi.

Here’s the result:


Pong and PacMan on the same screen, running simultaneously, with no slowdown. It’s pretty much the same code as in the Javascript version, but with C++ features (accessors, etc) added in, and some minor optimisation in the drawing routines. Cursor keys move PacMan around. Putting this together illustrated a few things:

  • It seems that it’s actually faster to use a SuperBitmap as a game’s display than it is to use a gadget and its GraphicsPort. Probably due to the large overhead associated with clipping.
  • There still appears to be a bug in the SuperBitmap::drawFilledRect() routine (possibly related to clipping to the bitmap’s size).
  • Drawing with the GraphicsPort outside of the gadget’s draw(Rect) function is a really bad idea unless you’re redrawing everything in a VBL event, because Woopsi doesn’t fire any events to tell you when a window needs redrawing (due to the way I’ve optimised gadget erasing, there’s no easy way to add this in, either).

There are a few bugs in the demo (PacMan doesn’t get drawn when the window first opens, ghosts can collide with PacMan diagonally, and it’s far too fast), but it suffices for a quick tech demo.

A few fixes. Windows are blocked from being dragged out of the top of the screen - I realised that if a screen is partially dragged down, it was possible to then drag a window out the top. It was then impossible to drag it back down again.

The ScreenTitle and WindowBorderTop make copies of the text passed into them to prevent them from referencing deleted strings - Jeff noticed this one a while ago. The BitmapButton offsets its bitmap blitting co-ordinates by 1 to take into account the border size (if the gadget has a border). The SuperBitmap’s draw(Rect) routine was basically a copy of GraphicsPort::drawBitmap(), so I’ve deleted the code from SuperBitmap and used a call to the GraphicsPort instead. Lastly, the demo skin’s buttons are slightly larger, and are now clickable on a real DS.

Some more new features. I’ve added a filled circle routine to the SuperBitmap and GraphicsPort classes, and the Pong demo now has a round ball. The new woopsiRGB() function performs the same function as PA_RGB (ie. it automatically sets the alpha bit in the value it returns). There are a few other minor changes involving optimisations, etc.