My first mobile game

I wanted to have a go at creating my first mobile game so I did some research to find out which tools people are using to do this. I found that games can be made for phones with J2ME (Java 2 Micro Edition) using the NetBeans IDE. Since this is my first J2ME game I just wanted to start with something straightforward. So I created a little game called “Worm” where you just have to collect as many fruit as possible.

Screenshots of game

The game is powered by the traditional game loop which updates and paints the screen. In the case of this game the loop waits for gradually decreasing intervals so that the game becomes more difficult as the player reaches higher scores:

public void run() {
    while (isRunning()) {
        process(this);
        repaint();
        waitTilNextFrame();
    }
}

The worm segments and the fruit store their row and column position in a grid which are then simply painted as squares. The cell size is calculated from the width and height of the canvas so that the game is playable on all screen sizes.

A high level look at the game’s classes:

Class diagram overview

It was a lot easier to develop a mobile game than I had anticipated. The most challenging part wasn’t implementing the game nor using the J2ME framework… but rather getting the drivers to work for my phone. It took me the best part of an hour to get the phone to talk to my computer.

Now that I understand the basics of J2ME I can’t wait to work on a slightly more ambitious project that perhaps has some animation and basic AI.