예제 #1
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()
예제 #2
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()
예제 #3
0
  private void processKey(KeyEvent e)
        // handles termination, help, and game-play keys
      {
    int keyCode = e.getKeyCode();

    // termination keys
    // listen for esc, q, end, ctrl-c on the canvas to
    // allow a convenient exit from the full screen configuration
    if ((keyCode == KeyEvent.VK_ESCAPE)
        || (keyCode == KeyEvent.VK_Q)
        || (keyCode == KeyEvent.VK_END)
        || ((keyCode == KeyEvent.VK_C) && e.isControlDown())) running = false;

    // help controls
    if (keyCode == KeyEvent.VK_H) {
      if (showHelp) { // help being shown
        showHelp = false; // switch off
        isPaused = false;
      } else { // help not being shown
        showHelp = true; // show it
        isPaused = true; // isPaused may already be true
      }
    }

    // game-play keys
    if (!isPaused && !gameOver) {
      // move the sprite and ribbons based on the arrow key pressed
      if (keyCode == KeyEvent.VK_LEFT) {
        jack.moveLeft();
        bricksMan.moveRight(); // bricks and ribbons move the other way
        ribsMan.moveRight();
      } else if (keyCode == KeyEvent.VK_RIGHT) {
        jack.moveRight();
        bricksMan.moveLeft();
        ribsMan.moveLeft();
      } else if (keyCode == KeyEvent.VK_UP)
        jack.jump(); // jumping has no effect on the bricks/ribbons
      else if (keyCode == KeyEvent.VK_DOWN) {
        jack.stayStill();
        bricksMan.stayStill();
        ribsMan.stayStill();
      }
    }
  } // end of processKey()