Example #1
0
  private void gameRender() {
    if (dbImage == null) {
      dbImage = createImage(PWIDTH, PHEIGHT);
      if (dbImage == null) {
        System.out.println("dbImage is null");
        return;
      } else dbg = dbImage.getGraphics();
    }

    // draw a white background
    dbg.setColor(Color.white);
    dbg.fillRect(0, 0, PWIDTH, PHEIGHT);

    // draw the game elements: order is important
    ribsMan.display(dbg); // the background ribbons
    bricksMan.display(dbg); // the bricks
    jack.drawSprite(dbg); // the sprites
    fireball.drawSprite(dbg);

    if (showExplosion) // draw the explosion (in front of jack)
    dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null);

    reportStats(dbg);

    if (gameOver) gameOverMessage(dbg);

    if (showHelp) // draw the help at the very front (if switched on)
    dbg.drawImage(
          helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null);
  } // end of gameRender()
Example #2
0
  public JackPanel(JumpingJack jj, long period) {
    jackTop = jj;
    this.period = period;

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

    setFocusable(true);
    requestFocus(); // the JPanel now has focus, 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, PHEIGHT, BRICKS_INFO, imsLoader);
    int brickMoveSize = bricksMan.getMoveSize();

    ribsMan = new RibbonsManager(PWIDTH, PHEIGHT, brickMoveSize, imsLoader);

    jack =
        new JumperSprite(
            PWIDTH,
            PHEIGHT,
            brickMoveSize,
            bricksMan,
            imsLoader,
            (int) (period / 1000000L)); // in ms

    fireball = new FireBallSprite(PWIDTH, PHEIGHT, imsLoader, this, jack);

    // prepare the explosion animation
    explosionPlayer =
        new ImagesPlayer("explosion", (int) (period / 1000000L), 0.5, false, imsLoader);
    BufferedImage explosionIm = imsLoader.getImage("explosion");
    explWidth = explosionIm.getWidth();
    explHeight = explosionIm.getHeight();
    explosionPlayer.setWatcher(this); // report animation's end back here

    // prepare title/help screen
    helpIm = imsLoader.getImage("title");
    showHelp = true; // show at start-up
    isPaused = true;

    // set up message font
    msgsFont = new Font("SansSerif", Font.BOLD, 24);
    metrics = this.getFontMetrics(msgsFont);
  } // end of JackPanel()
Example #3
0
  public void sequenceEnded(String imageName)
        // called by ImagesPlayer when the explosion animation finishes
      {
    showExplosion = false;
    explosionPlayer.restartAt(0); // reset animation for next time

    if (numHits >= MAX_HITS) {
      gameOver = true;

      score = (int) ((System.nanoTime() - gameStartTime) / 1000000000L);
      clipsLoader.play("applause", false);
    }
  } // end of sequenceEnded()
Example #4
0
  private void gameUpdate() {
    if (!isPaused && !gameOver) {
      if (jack.willHitBrick()) { // collision checking first
        jack.stayStill(); // stop jack and scenery
        bricksMan.stayStill();
        ribsMan.stayStill();
      }
      ribsMan.update(); // update background and sprites
      bricksMan.update();
      jack.updateSprite();
      fireball.updateSprite();

      if (showExplosion) explosionPlayer.updateTick(); // update the animation
    }
  } // end of gameUpdate()