Saturday 3 January 2009

Bat out of Hell!

When the good folk over at B3ta wondered what it would be like if "Bat out of Hell" were made into a PC game I couldn't resist.

The Brief:
"Guide a pixelly bat out from, well, hell. Rendered 1980s bleepy Spectrum style."

I made this and was featured in B3ta Issue #277, which made me very happy indeed.

Not quite sure why I decided to use Java rather than Flash for this though, as it was a massive pain in just about every way.

Java has no native support for sensible file formats such as MP3 (ok, I know there is a patent issue here but OGG would have been fine!) The clever folk over at Sun instead provide their own format (.au), which fails to compress so spectacularly well that even an encounter with a quantum singularity would probably provide little better than a 3-4% reduction in its packed size.

And whilst we're Java bashing:
  • Java is a real nightmare to deploy
  • Java is slow to load
  • The Java graphics engine appears to involve midgets and a crayon, painfully attempting to animate the screen in realtime.
There are some things that I could have done to improve performance. JOGL could have been used to provide hardware accelerated graphics, JLayer could have been used to provide MP3 playback, and the JNLPAppletLauncher seems to really help when deploying applets.

Anyway, if you're lucky enough to have Java setup in just the right way, there is a slim chance that below you'll see the game:



Controls: Left mouse button to fly upwards.

Want this game for you website or blog? Copy and paste the HTML code below:

<applet archive="http://www.rararadio.net/batHell.jar" code="Airplane" codebase="http://www.rararadio.net/batHell.jar" vspace="0" width="480" height="384" hspace="0"></applet>

5 comments:

  1. Good god what a mess. I took your game and decompiled it, the code looks like the midgets were looking for a career change. If you had written this correctly it would have run far faster than a flash implementation.

    Kids today, pff

    ReplyDelete
  2. It doesn't take a genius to figure out that the bottleneck is still Java. Use a profiler. So you can optimize the hell out of this code if you want, but you're basically wasting your time.

    As I said already, the only way you're really going to speed this up is to use something like JOGL to bypass the native Java graphics engine.

    What's wrong with my code anyway? It's well structured, it even uses GOF patterns, and it is one of the better Java games you will see online.

    ReplyDelete
  3. Oh come on really, use some sense. For years (especially before flash) people have been making games in java, and yet somehow yours manages to eat 100% of my cpu.

    Seeing as you have used transparent pngs in your game, and with a quick look at your code I can't see any optimization I suggest trying this:
    http://forums.sun.com/thread.jspa?threadID=5343141

    In the future when there is an obvious problem, look for a solution rather than blaming your tools.

    ReplyDelete
  4. I have to admit that I am not one to optimize code heavily, especially where it will compromise readability or sensible structure. Also, I had not expected better performance from this when I started given that it is software rendered and inherently slow. You can remove the game and see that the frame rate of just empty backbuffer to canvas can be pretty slow. With my backgrounds (far) I do not use transparency, and had assumed that Java would have noticed this and rendered it without. It may be the case that telling Java explicitly not to use transparency (even though there is none) could improve performance.

    Flash has a pretty smart method of detecting redraw regions that gives it a native performance boost. I'm not actually sure how well Flash would in reality perform on a game like this with parallax scrolling where 90% of the screen will always change (the black in the middle being the only part that doesn't).

    I still don't think Java is a great way to go for browser games. It is a lot harder in general to get things right, where Flash is much more forgiving.

    ReplyDelete
  5. I get
    ClassNotFoundException: Airplane

    ReplyDelete