Thursday, 27 October 2011

Do Androids Dream of Electric Sheep?

Soon they will. I am porting (or rather rewriting) The Silliness of the Lambs to Android. The game doesn't need much processing power, the gameplay is quite casual, and it's control mechanics is ideal for touchscreen devices, so the idea to make a smartphone version came quite naturally. It is possible to play the original on a phone in the browser, but it's too slow, and I wanted to get into Android programming anyway.

So I went to, learned the basics of Android development, installed JDK + Eclipse + Android SDK, and started to discover the platform and tried to build up the basics for the game. I was surprised to find that developing for Android is as easy as stomping on kittens. My pessimist self expected that I would have to build the Java project, then manually convert it to an Android package, then somehow transfer it to my phone where I can finally run it. Instead of this I just have to click on the Run button, lean back in my chair, and all of the tasks is done automagically. If my phone is connected to the dev computer through USB then the program is run on it, otherwise the emulator is started and my program is run inside it. On a second thought this is what I really expect of a development environment.

After discovering the possibilities I decided to use OpenGL ES for rendering. I have made a simple program which created an OpenGL display and drew a flat shaded triangle, and then extended it step-by-step, added handling of touch events, controlling fps, implemented texture loading and drawing of textured rectangles. At this point I had a basic engine with the functions I needed, so I could start porting the game source. Since Processing is quite similar to Java it did not seem to be too hard, though it wasn't easy. Java needs lots of "decoration" (public final static abstract...), classes go to separate files, the libraries have different functions, etc.

During the porting/rewriting I could restructure the code, so it is organized better now. I have redesigned some aspects of the implementation of the game, e.g.  instead of a tiled background (which determined both the graphical appearance of the level and the physical representation) I use one big background image (graphical appearance) and the physical objects (e.g. walls) are now stored independently. This modification speeded up both rendering and collision detection. The levels are not inlined in the code anymore but loaded at runtime from xml resources.

So now I have a (gameplay-wise) mostly functional version for Android. This means that I am ready with the 90% of the project, now I just have to finish the remaining 90%. I have to implement font rendering, create a menu or level selecting screen, create levels and other contents, and I also plan to add sound effects and maybe music. After it's finished I would like to release it on Android market. I intend to release a demo soon so that you can try it if you are interested.

Some images as usual (please note that some parts of the graphics are just placeholders :)

In the emulator:

On my phone:

P.S. I have watched Blade Runner to have some right to use this title :) I will also read the book.