Exemplo n.º 1
0
  @Override
  public void update() {

    if (GameData.getphase() == PHASE.TWO || GameData.getphase() == PHASE.THREE) {
      bonus.setActive(true);
      bonus.update();
    }

    if (blinking) {
      long elapsed = (System.nanoTime() - blinkTimer) / 1000000;
      if (elapsed > 1000) {
        blinking = false;
      }
    }

    // set boundaries of the ship (player):
    // on X axis
    if (x <= GamePanel.WIDTH - playerImage.getWidth(null) / 2) {
      x = GamePanel.WIDTH - playerImage.getWidth(null) / 2;
    }

    if (x > GamePanel.PWIDTH + playerImage.getWidth(null) / 2) {
      x = GamePanel.PWIDTH + playerImage.getWidth(null) / 2;
    }

    // on Y axis
    if (y < GamePanel.HEIGHT - playerImage.getHeight(null) / 2) {
      y = GamePanel.HEIGHT - playerImage.getHeight(null) / 2;
    }

    if (y > GamePanel.PHEIGHT - playerImage.getHeight(null) / 2) {
      y = GamePanel.PHEIGHT - playerImage.getHeight(null) / 2;
    }
  }
Exemplo n.º 2
0
  @Override
  public void render(Graphics g) {
    if (blinking) {
      long elapsed = (System.nanoTime() - blinkTimer) / 1000000;
      if (elapsed / 100 % 2 == 0) {
        return;
      }
    }
    g.drawImage(playerImage, (int) x, (int) y, null);

    if (GameData.getphase() == PHASE.TWO || GameData.getphase() == PHASE.THREE) {
      bonus.render(g); // render the bonus system
    }
  }