// Draws the Battle Menu
  public void drawMenu(Graphics g) {
    if (scene == BATTLE) {
      // Background
      g.setColor(new Color(0, 100, 0));
      g.fillRect(0, 450, 800, 150);
      g.setColor(Color.BLACK);
      g.fillRect(10, 460, 780, 130);

      // Player
      // Health
      g.setColor(Color.WHITE);
      g.setFont(new Font("Bell MT", Font.BOLD, 20));
      FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
      int hgt = metrics.getHeight();
      // Hgt = 26
      int adv = metrics.stringWidth(player.getHealth() + "/" + player.getMaxHealth(0));
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 470, 150, hgt - 6);
      if ((double) player.getHealth() / player.getMaxHealth(0) > .25) g.setColor(Color.RED);
      else g.setColor(player.getLowHealth());
      g.drawString(
          player.getHealth() + "/" + player.getMaxHealth(0), getWidth() - adv - 180, 461 + hgt);
      g.fillRect(
          getWidth() - 167,
          473,
          (int) (144 * player.getHealth() / player.getMaxHealth(0)),
          hgt - 12);

      // Stamina
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 500, 150, hgt - 6);
      adv = metrics.stringWidth((int) player.getStamina() + "%");
      if (player.getStamina() < 33.3) g.setColor(Color.WHITE);
      else if (player.getStamina() == 100) g.setColor(Color.GREEN);
      else g.setColor(Color.CYAN);

      g.drawString((int) player.getStamina() + "%", getWidth() - adv - 180, 491 + hgt);
      g.fillRect(getWidth() - 167, 503, (int) (144 * player.getStamina() / 100), hgt - 12);

      // Basic Attack
      adv = metrics.stringWidth("Kick Dirt");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 470, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Kick Dirt", 25, 492);

      // Spell 1
      adv = metrics.stringWidth("Hurl Pebble");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 510, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Hurl Pebble", 25, 532);
    }
  }
示例#2
0
 public static void Start(Player player, Level level, Enemy enemy) {
   System.out.println(player.getCharName() + " Health: " + player.getHealth());
   System.out.println(enemy.getName() + " " + enemy.getType() + " Health: " + enemy.getHealth());
   System.out.println("Level: " + level.getLevelType());
   int choice = ChooseAttacks();
   CalculateDamage(choice, player, level, enemy);
 }
  @Override
  public void draw(Graphics2D g) {
    g.setColor(Color.white);
    g.drawString("Score: " + SCORE, 5, 15);

    g.setColor(Color.red);
    g.drawString("Health: " + player.getHealth(), 5, 35);

    blocks.draw(g);
    player.draw(g);
    level.draw(g);

    if (level.isGameOver()) {
      g.setColor(Color.red);
      g.setFont(gameScreen);
      String gameOver = "GAME OVER!";
      int gameOverWidth = g.getFontMetrics().stringWidth(gameOver);
      g.drawString(gameOver, (Display.WIDTH / 2) - (gameOverWidth / 2), Display.HEIGHT / 2);
    }

    if (level.isComplete()) {
      g.setColor(Color.green);
      g.setFont(gameScreen);
      String complete = "LEVEL COMPLETE!";
      int completeWidth = g.getFontMetrics().stringWidth(complete);
      g.drawString(complete, (Display.WIDTH / 2) - (completeWidth / 2), Display.HEIGHT / 2);
    }
  }
示例#4
0
 @Override
 public void update(OWorld oworld, EntitySitting sitentity, OEntityPlayerMP eplayer) {
   PluginLoader.HookResult autoHeal = etc.getInstance().autoHeal();
   if ((oworld.q != 0 || autoHeal != PluginLoader.HookResult.DEFAULT_ACTION)
       && autoHeal != PluginLoader.HookResult.ALLOW_ACTION) {
     Player player = new Player(eplayer);
     if (player.getHealth() < 20 && eplayer.bT % this.RATE * 12 == 0) player.increaseHealth(1);
   }
 }
示例#5
0
  public void draw(Graphics2D g) {
    g.drawImage(image, 0, 10, null);
    g.setColor(Color.WHITE);
    g.setFont(font);
    g.drawString(player.getHealth() + "/" + player.getMaxHealth(), 30, 25);
    g.drawString(player.getFire() / 100 + "/" + player.getMaxFire() / 100, 30, 45);
    g.drawString(" " + LevelCompletedState.score / 1, 15, 67);

    g.setColor(java.awt.Color.WHITE);
    g.drawString(player.getTimeToString(), 367, 24);
  }
示例#6
0
  public Battle(Player p, Monster m) {
    while (p.getHealth() < 0 && m.getHealth() < 0) {
      System.out.println(">What will you do?");
      String s = scan.next();

      if (s.equals("fight")) {
        p.attack(m);
        p.takeDamage(m.getDamage());
        m.attack(p);
        m.takeDamage(p.getDamage());
      }
    }
  }
  public void playerCollision(Player player, WorldManager worldManager, float delta) {

    Vector2 playerProjection = new Vector2(player.getPlayerPosition());
    Vector2 playerAcc = new Vector2(player.getPlayerAcceleration());
    playerAcc.x = 0;
    playerProjection.add(playerAcc.tmp().mul(delta));

    Chunk collidingChunk =
        worldManager.getWorld().getChunkAt(playerProjection.x, playerProjection.y);

    if (collidingChunk != null) {

      for (int x = 0; x < chunkSizeX; x++) {

        for (int y = 0; y < chunkSizeY; y++) {

          if (playerProjection.x >= (collidingChunk.getChunkX() + (x * blockSizeX))
              && playerProjection.x
                  <= (collidingChunk.getChunkX() + (x * blockSizeX) + blockSizeX)) {

            if ((playerProjection.y >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjection.y
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))
                || (playerProjection.y + 32 >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjection.y + 32
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))) {

              Byte[][] chunkData = collidingChunk.getChunkData();

              if (blockTypes.isVisible(chunkData[x][y])) {

                if (player.getVelocityY() < player.getFallDamageThreshold()) {

                  player.setHealth(
                      player.getHealth()
                          - Math.round(
                              (Math.abs(player.getVelocityY())
                                  / player.getFallDamageMultiplier())));
                }

                player.setVelocityY(0);
                player.setOnFloor(true);
              }
            }

          } else if (playerProjection.x + 16 >= (collidingChunk.getChunkX() + (x * blockSizeX))
              && playerProjection.x + 16
                  <= (collidingChunk.getChunkX() + (x * blockSizeX) + blockSizeX)) {

            if ((playerProjection.y >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjection.y
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))
                || (playerProjection.y + 32 >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjection.y + 32
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))) {

              Byte[][] chunkData = collidingChunk.getChunkData();

              if (blockTypes.isVisible(chunkData[x][y])) {

                if (player.getVelocityY() < player.getFallDamageThreshold()) {

                  player.setHealth(
                      player.getHealth()
                          - Math.round(
                              (Math.abs(player.getVelocityY())
                                  / player.getFallDamageMultiplier())));
                }

                player.setVelocityY(0);
                player.setOnFloor(true);
              }
            }
          }
        }
      }

      Vector2 playerProjectionY = new Vector2(player.getPlayerPosition());
      Vector2 playerAccY = new Vector2(player.getPlayerAcceleration());
      playerAccY.y = 0;
      playerProjectionY.add(playerAccY.tmp().mul(delta));

      for (int x = 0; x < chunkSizeX; x++) {

        for (int y = 0; y < chunkSizeY; y++) {

          if (playerProjectionY.x >= (collidingChunk.getChunkX() + (x * blockSizeX))
              && playerProjectionY.x
                  <= (collidingChunk.getChunkX() + (x * blockSizeX) + blockSizeX)) {

            if ((playerProjectionY.y >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjectionY.y
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))
                || (playerProjectionY.y + 32 >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjectionY.y + 32
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))) {

              Byte[][] chunkData = collidingChunk.getChunkData();

              if (blockTypes.isVisible(chunkData[x][y])) {

                player.setVelocityX(0);
              }
            }

          } else if (playerProjectionY.x + 16 >= (collidingChunk.getChunkX() + (x * blockSizeX))
              && playerProjectionY.x + 16
                  <= (collidingChunk.getChunkX() + (x * blockSizeX) + blockSizeX)) {

            if ((playerProjectionY.y >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjectionY.y
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))
                || (playerProjectionY.y + 32 >= (collidingChunk.getChunkY() + (y * blockSizeY))
                    && playerProjectionY.y + 32
                        <= (collidingChunk.getChunkY() + (y * blockSizeY) + blockSizeY))) {

              Byte[][] chunkData = collidingChunk.getChunkData();

              if (blockTypes.isVisible(chunkData[x][y])) {

                player.setVelocityX(0);
              }
            }
          }
        }
      }
    }
  }