Game programming under 4096 bytes

So this year I decided to give the Java 4K programming contest a try. I’ve been learning some Flash game programming techniques lately, but decided it be fun to try to create a little retro game with the same code size as some of the old classics (Space Invaders, Asteroids).
So far, it looks like a big challenge. I have the basic character movement and fire controls working, but the game is already 2.4K in a compressed jar! When I use an open source obfuscator, it reduces it to around 1.8K, so I’m already getting to the halfway mark and I haven’t put in the enemy and hit detection to start making it … well, fun.
However, this is fun. I started programming at an early age because I wanted to make games in my Apple //c and my calculator. It’s a good idea to learn how to program by making games, since game programming requires you to deal with user interface design, computer graphics, animation, a bit of AI, performance techniques, and many other aspects of Computer Science.
Hopefully I can finish the game and post it here, but don’t wait for anything earth shattering though, this is looking pretty primitive so far. With the 4K limit, I can’t even really put any sprites that look interesting, and I’m thinking of just using basic shapes for the characters. I’ve also had to do little tricks like;
- Use arrays instead of classes (or inner classes)
- For event handling, use processEvent(AWTEvent) instead of listeners
- Inline methods whenever possible
The last one confuses me a bit. I put some logic to detect if a bullet or character was out of bounds, since this was repeated a bit in the code. But when I added the method it actually increased the class size by 10s of bytes, which I didn’t expect. I’m guessing it’s just the overhead of a method definition, so I’m trying to keep the number of methods I’m using to a minimum.
If anybody has any good size byte code reduction techniques, not including coding directly in bytecode of course, let me know. I’m also looking for recommendations on good open source obfuscators. So far I’m using JavaGuard, which has a nice front end to it.
Filed under: Java, Software Development on February 1st, 2007

Leave a Reply