Mischiefblog
I make apps for other people

Radar: almost to a proof of concept

Posted by Chris Jones
On October 10th, 2005 at 13:25

Permalink | Trackback | Links In |

Comments (1) |
Posted in Design Journal, Java, Python

I’ve been working on and (mostly) off on some kind of multiplayer online game. I’ve had ideas, as you may have read, but not a lot of free time to implement much of anything and a lot of what I have done in the past is mostly invisible: figuring if object heirarchies or generic structures work better, experimenting with different persistence options and implementations, developing and testing networking and protocols, thin client implementations, exploring different development processes, etc.

It’s well enough to say, “Get on with it!” and “Shut up and code!”–I have, but I don’t have someone paying me to do this kind of coding on a daily basis, so what I end up creating turns into snippets and small, apparently failed projects littering my IDE. One consistency, though, has always been trying to build what tools and utilities I anticipate needing first, and actually implementing the game later. While I still don’t have a game, as such, this time I’m trying it the other way: starting with the client, and coding the server and utilities to provide what the client wants. I tried this before in Java, and got a very nice client that proved that my single Java server could handle several thousand active connections from a single client before the client died (each client connection had a separate message processor thread)–this was on one machine, of course.

This client is simple, written in Python, and using Pygame (aka, libSDL wrappers for Python). Embarassing source code for this demonstration is available, which shows that the client has a simple, reliable way of presenting world state through the use of update method calls to sprites, as well as properly samples user input (without eating the CPU) for submission to the server.

Release Notes

This was developed with Python 2.4 and the binary Pygame 1.7.0 with SDL on Win32. It should work well on any system with Python 2.4 or higher, and Pygame 1.7.0 or higher. The demo was developed using Eclipse 3.1 with PyDev 0.9.6 (auto-updated to 0.9.8.1 features).

When Pygame is properly installed in the Python installation’s Lib/site-packages directory, you may be able to start the demo either from the command line (if the SDL libraries are in your path) and definitely should be able to start it through IDLE.

1) Start IDLE
2) Open the radar.py file
3) Select “Run | Run Module…” or press F5 to start it

When using IDLE to run the demo, press Escape in the application window, or hit CTRL-C in the IDLE window to end it. Running under Eclipse properly handles the Close Window/shutdown event.

By default, logging to stdout is commented out in the logger.py module: IDLE doesn’t handle that as well as Eclipse.

Move the blue arrow around with the arrow keys.

Ugly things:

  • Because of how transparency is handled, I had to increase the size of each sprite’s image–I made this one pixel per side to keep the image centered. The obvious fix (pull the transparent pixel ColorKey from another point in the image) didn’t work.
  • I wrote my own logging module instead of using the Log4Py-equivalent (Python logging module)
  • Rotation degrees and movement speeds are hard-coded
  • I haven’t implemented any kind of collision detection
  • I’m generating more events/method calls for movement than needed: holding down movement key will generate one event (and method call) as often as every 10 milliseconds, or up to 100 calls per second. Modern PCs can handle this without a problem, but it still bugs me.
  • The code is barely commented. Some people argue that Python is self documenting, but I must differ in my opinion.
  • Since this was my first Pygame app, I liberally lifted code from examples to get things on the screen

Ideas for improvement:

  • Close the log when catching the shutdown event
  • Make the fake players less random
  • Use the ConfigParser module to allow configuration from a data file

Future plans:

  • Remove the fake players
  • Network enable the client
  • Write a simple mirror server to allow multiple clients to see one another
  • Support text chat

One Response to “Radar: almost to a proof of concept”

  1. Abalieno Says:

    Ah, wishes.. ;p