Beispiel #1
0
  @Override
  public void draw(Graphics2D g) {

    try {
      //			g.drawImage(bg.getScaledInstance(GamePanel.WIDTH * GamePanel.SCALE, GamePanel.HEIGHT *
      // GamePanel.SCALE, 0),
      //					0,
      //					0,
      //					null
      //					);
      if (paused) {
        pauseMenu.draw(g);
      } else {
        if (tileMap != null && player != null) {
          if (textEventListener != null && textEventListener.isPlaying()) {
            textEventListener.draw(g);
          } else {

            g.drawImage(
                bg.getScaledInstance(
                    GamePanel.WIDTH * GamePanel.SCALE, GamePanel.HEIGHT * GamePanel.SCALE, 0),
                0,
                0,
                null);
            player.draw(g);
            tileMap.draw(g);
          }

          g.setColor(Color.BLACK);
          g.setFont(new Font("Times New Roman", Font.BOLD, 10));
          g.drawString("Health", 60, 10);
          g.setColor(Color.RED);
          g.drawRect(75, 15, player.getMaxHealth() * 10, 10);
          g.fillRect(75, 15, player.getHealth() * 10, 10);

          g.drawImage(amulet, 0, 0, null);
          if (gsm.getFire()) g.drawImage(firePendant, 0, 0, null);
          if (gsm.getAir()) g.drawImage(airPendant, 0, 0, null);
          if (gsm.getWater()) g.drawImage(waterPendant, 0, 0, null);
          if (gsm.getEarth()) g.drawImage(earthPendant, 0, 0, null);
        }
      }
      if (player.isDead()) {
        g.setFont(new Font("Times New Roman", Font.BOLD, 30));
        g.setColor(Color.RED);
        g.drawString("You are dead", 50, 50);
      }

    } catch (NullPointerException e) {
      System.out.println("Shit be null");
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #2
0
 @Override
 public void update() {
   if (textEventListener != null) {
     if (!textEventListener.isPlaying()) {
       textEventListener.playMessage(
           player.getX() / TileMap.tileSize, player.getY() / TileMap.tileSize);
     } else {
       textEventListener.update();
     }
   }
   if (tileMap != null && player != null && !paused && !textEventListener.isPlaying()) {
     if (!player.isDead()) player.update();
     tileMap.center(player.getX(), player.getY());
     tileMap.update(player);
   }
 }
  public void update() {
    player.update();
    player.checkAttack(enemies);

    finish.update();
    finish.checkGrab(player);

    System.out.println(player.getx());
    System.out.println(player.gety());

    bg.setPosition(tileMap.getx(), tileMap.gety());

    tileMap.setPosition(GamePanel.WIDTH / 2 - player.getx(), GamePanel.HEIGHT / 2 - player.gety());

    if (player.isDead()) {
      player.setPosition(130, 2375);
      player.revive();
      player.reset();
      restart();
    }

    //		for(int i = 0; i < drinks.size(); i++){
    //			Alcohol a = drinks.get(i);
    //			a.update();
    //			if(a.shouldRemove()){
    //				drinks.remove(i);
    //				i--;
    //			}
    //		}
    //
    for (int i = 0; i < enemies.size(); i++) {
      Enemy e = enemies.get(i);
      e.update();
      if (player.isDrunk()) {
        e.kill();
      }
      if (e.isDead()) {
        enemies.remove(i);
        e.addScore(Level2State.score);
        i--;
      }
    }

    bg.setPosition(tileMap.getx(), tileMap.gety());
  }