Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

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 it

The 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();  }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page