Game Development Reference
In-Depth Information
It checks for a valid base folder. This is the folder that contains the game files. By
default it points to /data/data/PACKAGE_NAME/files .
It installs the game files (if required). Game files for the shareware PC version of
Wolf 3D follow:
Audio : audiohed.wl1 and audiot.wl1
Graphics : config.wl1 , gamemaps.wl1 , and maphead.wl1
VGA : vgadict.wl1 , vgagraph.wl1 , vgahead.wl1 , and vswap.wl1
It defines the game arguments: the game label, ID, and base folder. Game IDs are
wolf (for the retail version) and wolfsw (for shareware).
It loads the native library using the system call System.load(LIBRAY_NAME) .
It sets up a listener to the natives interface class. This allows the game to receive
messages from the native layer.
It creates an instance of the AudioManager . This class is in charge of playing
background music or sound events received from the native layer.
It starts a new thread with the main game loop. The thread is required because the
native game loop will block execution.
At this point, the game will start, and native events will begin cascading into the Java layer.
Listing 6-5. The Game Loop from the Main Activity
/**
* Start the main game loop
* @param baseDir
* @param game
* @param portrait
*/
private void startGame(String baseDir, String game, boolean portrait) {
File dir = new File(baseDir);
if (!dir.exists()) {
if (!dir.mkdir()) {
MessageBox("Invalid game base folder: " + baseDir);
return;
}
}
// setup game files
try {
WolfTools.installGame(this, dir);
} catch (Exception e) {
MessageBox("Fatal Error", "Unable to set game files:"
+ e.toString());
Search WWH ::




Custom Search