Design

The Ghosts MIDlet allows you to use multipoint touch functionality in a simple game. The multipoint touch functionality is used to emulate a game pad consisting of an analog stick and a fire button. The virtual analog stick behaves in a similar way to a traditional analog joystick: the thumb can be moved to any direction inside the stick range. The moving thumb provides the game information about its position relative to the center of the stick range.

The following figure shows examples of the MIDlet main view.

Figure: Ghosts main view

To play the game, move the crosshair on the screen using the virtual analog stick. When you have managed to aim the crosshair at a ghost, select FIRE to shoot it. To exit the game, select EXIT.

The MIDlet consists of the following classes:

  • Ghosts—MIDlet main class, which displays the Scene class.

  • Scene—Implements the main game logic. This class generates the game's world clock for the rest of the game classes, passes pointer events (received though the pointerPressed, pointerDragged, and pointerReleased methods) to the game pad, and retrieves pointer number information with the getPointerEventId method.

  • Gamepad—Implements the multipoint touch on-screen game pad. This class uses pointer events from the Scene class to update the analog stick position and the fire button status.

  • Crosshair—Used for aiming. The Crosshair class uses the player input provided by the Gamepad class.

  • Ghost—Implements the ghost behavior. The ghost sets its position on the screen and waits a while to allow the player to aim and shoot. During the waiting period, the ghost moves a little. When the ghost is shot and hit, it changes its appearance for a moment before repositioning on the screen. To increase the game difficulty, the waiting period is reduced after a successful hit.

  • Point and Size—Auxiliary classes used for position and size handling.

For information about implementing the MIDlet, see section Implementation.