Satya's blog - Trying to make a train game

Sep 30 2007 23:00 Trying to make a train game

This weekend I've been trying to write a train game. Graphical, top-down simulation of railway tracks and yards. And I'm doing it in Python using PyGTk and PyGame.

Why that language and those GUI (graphical user interface) frameworks? Because over 2 years ago, some people convinced me that if I was going to make a graphical game, NOT in a web browser, then pygame was the thing to use. Pygame is obviously Python. So I'm having to learn Python, while trying to write a graphical native-OS (not browser) game. My forté is web programming, where the UI is built for you and the UI programming language (HTML) is dead simple. This is a big change.

So, 2 years ago, I built a few Python classes that could throw up an SDL window, draw a single track, and let me run a single train along it. Nothing dynamic, track and train hard-coded, only able to control direction and speed. It didn't even have acceleration. At that time I had started with the game's core.

This weekend I decided to start on the user interface. I needed something that would work across platforms (which does not mean "Oh we have both kinds, XP *and* 2000!") and wouldn't be too hard.

I considered switching to Java, another language that's new to me. The advantage would be, I could be forced to learn Java. That was also the disadvantage. I considered Javascript, the advantage being I am already deeply familiar with web programming. The disadvantage is that Javascript has very little drawing capability; some libraries are available that apparently simulate lines with div tags. Horrible. It works, but still! Besides, having hundreds of lines (track segments) would probably be slow and memory intensive, since each tiny div drags along its entire DOM object definition with it.

So, back to Python. It's a good language to learn, I've been told. And I've already got the afore-mentioned code samples. Okay, so I need to generate a user interface. Enter PyGtk (however it's capitalised). After a few false starts, I have a File->Open menu and now I can create a pygame drawing surface and I'm ready to show a map.

Then I find Rail World and Freight Yard Manager (FYM), which completely take away my motivation for doing this. They seem so slick, and better. And compatible with Yard Duty, the now-defunct but still being run original top-down freight rail simulation. Lots of bugs, no longer maintained, but still in use. And has hundreds of maps. Whose lack of Linux-compatibility and un-maintenance inspired me to start my project in the first place.

Then I find out that Rail World won't work with my Java for some reason, and FYM just plain won't run even with what I think is an appropriate .NET version (and won't run in wine, the windows emulator on Linux). Oh, and FYM is Windows-only. So, I might do my game after all :-) It does need to be compatible with Yard Duty, and that sucks. Maybe a converter, but first let me get *something* working.

Update: Rails World does work -- with Sun Java 6, which you have to enable on Ubuntu thus:
install the Sun Java 6 packages (sun-java6-*), edit /etc/jvm to include the line:
/usr/lib/jvm/java-6-sun
and run:
update-alternatives --config java
(as root)

Last updated: Oct 01 2007 15:46

Tag: geeky