[an error occurred while processing this directive] [an error occurred while processing this directive]
home games downloads blog about
 
12/07/06 A Reuseable J2ME Bleutooth Game Framework - well almost ;-)

Lets take a look at some other classes...

SplashScreen.java - Extends Canvas Implements Runnable
I wont go into this too much except to say I had the attitude if it aint broke dont fix it. This was taken from a nokia example and tweaked.
At the start of the thread, a call to init() in the midlet class is ran and on exit a call to midlet.splashScreenDone().
A splash screen is loaded and displayed for 1.5 seconds before the thread terminates. If the user presses a key the thread will also terminate.

Dictionary.java
Again this has the nokia header and was taken from one of their example programs. The objective of this class is to load the contents of a text file and store the lines from the text file in to an array of Strings.
The text file is in UFT-8 format. It is loaded into memory and converted into a String, and then each line is put into its own String. There is a block of code commented out that should be used for nokia mobiles due to some strange bug when reading in a file.
The getString(int id) method is used to return a string for one of the lines who's id you provide. If you're unsure about what I mean here then just look in the GMCanvas class for examples on the usage of getString(int id).

Game Effects.java - implements Control
This is my quick and dirty effort at handling sound. It wont work on all mobiles due to the number of different issues in playing sounds across all mobiles but I've included a couple of variations that you should look at in the Includes directory.
These examples include pre-processor directives for compiling with Antenna, but you should be able to get a general idea of what needs to be done to get sound working on the various mobiles.

GameEffects()
Calls createSoundPlayer to load the sounds that are to be used. There's also some commented out code that can be used to identify the supported types.

Player createSoundPlayer(String filename, String format)
Loads a sound.

setIsPaused(boolean isPaused)
stopSound()
void pause()
resume()

Used when the game is paused or resumed.

playSound(int priority, Player p, int vol, int loop)
Plays a cound. Only one sound can be played at a time and priorities are given to the sounds so that one sound can override another. If this happens then the sound that was playing is stopped.

playPop()
playMenu()
playEOL()
playEOG()

Custom to this game but should give you an idea of how the sounds are played etc

Standard.java
I created this class before I decided to do a game framework. The idea was to put some reusable methods in one class to help speed up development time. This class contains some useful methods for display text.
Instead of using a bitmap font I've always used the system font, partly because I thought it would save me some hassle when it came to localization but mainly because I was too lazy to make my own bitmap font.

setSoftKey(Canvas c)
This is an attempt to aquire the softkey code for the mobile you are using. For an upto date version I'd visit j2meforums.com.

createImageText(int index, Font f, StringBuffer b)
The idea behind this method is to create an Image that contains a text string. This is because its quicker to draw a single image than it is a text string. The static variable imageText (just above this method in the code) should be changed to allow for the amount of images you require. Again, I've commented out some nokia code. If you're running on a nokia then put it back in and comment out the code below.

drawThickText(...)
Draws a string 9 times to give it a border. I only use this with the createImageText(...) method above for obvious reasons.
Among other variables you provide a StringBuffer containing the text you wish to display, an x,y, border color and main color.

boxWrap(...)
wrapper(...)
wrapper2(...)
wrapperLines(...)

I use these to display text within a rounded rectangle. They are not the easiest methods to follow or use come to that.
You need to run wrapperLines(...) to setup the box with the text you want to display and boxWrap(...) to display the box with the text.
The reason for this is wrapperLines(...) calculates amount of lines to display and the amount of text lines in total (for scrolling purpose).

myTicker(...)
Provides a scrolling text function. There are some variables just above the method that require some setup.

openRecordStore(StringBuffer buf)
closeRecordStore()
getSettings(GMCanvas gm)
setSettings(GMCanvas gm)
setGame(GMCanvas gm)
getGame(GMCanvas gm)

Some RMS related stuff. I keep the general game settings such as sound on/off, continue available, highscores in one RMS record and actual game data in another RMS record.

The rest of this class contains High score methods that I've had to butcher due to the fact that I use an online highscore table along with an on phone highscore table so as a result the highscore code may need a tweak along the way.

BGLayer.java
This class handles a multi directioanl scrolling background. I'll give you a decent explanation at some point as to what is going on here, but for now I'll briefly explain the classes.

BGLayer(...)
This sets up a few variables but most importantly it creates the background image that we draw the tiles on.

scrollTiles(int[])
Fills the background layer with tiles based on the one dimentional array provided.

setCell(...)
Set an individual tile on the background.

show(...)
Puts the background image on to the main screen (or rather specified graphics context).

Lift(...)
Moves the background image 16 pixels upwards and updates the bottom portion of the image with new tile information. I used this when the level was complete, to scroll in the next level.

desiredScrollPos(...)
You give this method a desired x & y scroll position and it works out how fast its going to move the background image based on your desired position and the current possition. I used this to make the scrolling smooth. It may not be ideal for all games but its here if its needed.

move(...)
setScrollX(...)
setScrollY(...)

Move the background and update any edges that may need updating.
Called by desiredScrollPos().

Bluetooth.java
For now this is almost an empty class. This is so noobs can compile the framework in the WTK without any problems.
I discuss this class in detail shortly.

NOTE: This blog is not yet finished. Over the course of the next few days I'll be updating the source code with some relevant comments along with this blog so you may need to download the file again.


Previous
[an error occurred while processing this directive]