Start Jack Jumping
JumpingJack fixes the frame rate at 30 FPS; anything faster makes it almost impossible to control Jack. The illusion of speed is governed by how fast the bricks and image ribbons move, which is controlled by a single moveSize variable in the BricksManager
class. moveSize specifies the distance that the bricks layer should be shifted in each update of the animation loop.
It loads and starts playing a "Jumping Jack Flash" MIDI file using the MidisLoader class developed in Chapter 8:
// global
private MidisLoader midisLoader;
midisLoader = new MidisLoader();
midisLoader.load("jjf", "jumping_jack_flash.mid");
midisLoader.play("jjf", true); // repeatedly play itThe file is played repeatedly until it's stopped as the application window closes:
// global
private JackPanel
jp; // where the game is drawn
public void windowClosing(WindowEvent e)
{ jp.stopGame(); // stop the game
midisLoader.close();
}
JumpingJack sets up window listener methods for pausing and resuming the game, in a similar way to the BugRunner application in Chapter 11. For example, window iconification/deiconification causes the game in the JackPanel object, jp, to be paused/resumed:
public void windowIconified(WindowEvent e)
{ jp.pauseGame(); } // jp is the JackPanel object
public void windowDeiconified(WindowEvent e)
{ jp.resumeGame(); }