The Animation Framework

JackPanel is a subclass of JPanel and implements the animation framework described in Chapters 2 and 3; JackPanel resembles the BugPanel class of Chapter 11.

The JackPanel() constructor in Example 12-1 creates the game entities: the RibbonsManager, BricksManager, JumperSprite, and FireBallSprite objects. It prepares the explosion animation and the title/help screen.

Example 12-1. The JackPanel constructor

    // some of the globals
    private JumpingJack jackTop;
    private JumperSprite jack;          // the sprites
    private FireBallSprite fireball;
    private RibbonsManager ribsMan;     // the ribbons manager
    private BricksManager bricksMan;    // the bricks manager

    // to display the title/help screen
    private boolean showHelp;
    private BufferedImage helpIm;

    // explosion-related
    private ImagesPlayer explosionPlayer = null;
    private boolean showExplosion = false;
    private int explWidth, explHeight;   // image dimensions
    private int xExpl, yExpl;   // coords where image is drawn


    public JackPanel(JumpingJack jj, long period)
    {
      jackTop = jj;
      this.period = period;

      setDoubleBuffered(false);
      setBackground(Color.white);
      setPreferredSize( new Dimension(PWIDTH, PHEIGHT));

      setFocusable(true);
      requestFocus();    // so receives key events

      addKeyListener( new KeyAdapter() {
        public void keyPressed(KeyEvent e)
        { processKey(e); }
      });

      // initialise the loaders
      ImagesLoader imsLoader = new ImagesLoader(IMS_INFO);
      clipsLoader = new ClipsLoader(SNDS_FILE);

      // initialise the game entities bricksMan = new BricksManager(PWIDTH, ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.