Пример #1
0
 public void mouseClicked(MouseEvent e) {
   if (scene == BATTLE) {
     if (!battleWon) {
       int target = 0;
       if (kickDirt.contains(mX, mY) && player.getStamina() >= 33.3 && !player.getDeath()) {
         spellsThrown.add(
             new Spell(
                 0,
                 new Color(153, 76, 0),
                 player.centerX(),
                 player.centerY(),
                 enemies.get(target).centerX(),
                 enemies.get(target).centerY(),
                 target));
         player.staminaGain(-333);
       }
       if (hurlPebble.contains(mX, mY) && player.getStamina() >= 100 && !player.getDeath()) {
         spellsThrown.add(
             new Spell(
                 1,
                 Color.LIGHT_GRAY,
                 player.centerX(),
                 player.centerY(),
                 enemies.get(target).centerX(),
                 enemies.get(target).centerY(),
                 target));
         player.staminaGain(-1000);
       }
     }
   }
 }
Пример #2
0
  // 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);
    }
  }
Пример #3
0
  // Hotkeys!
  public void keyPressed(KeyEvent e) {
    int keyID = e.getKeyCode();

    if (scene == OVERWORLD) {
      if (keyID == KeyEvent.VK_UP || keyID == KeyEvent.VK_W) {
        moveUp = true;
      }
      if (keyID == KeyEvent.VK_DOWN || keyID == KeyEvent.VK_S) {
        moveDown = true;
      }
      if (keyID == KeyEvent.VK_LEFT || keyID == KeyEvent.VK_A) {
        moveLeft = true;
      }
      if (keyID == KeyEvent.VK_RIGHT || keyID == KeyEvent.VK_D) {
        moveRight = true;
      }

      if (keyID == KeyEvent.VK_ENTER) {
        // Toggle the visible state of the Game Menu
        Boolean visibleState = menuScreen.isVisible();
        menuScreen.setVisible(!visibleState);
      }

      for (int enemyNum = 0; enemyNum < enemies.size(); enemyNum++) {
        Enemy enemy = enemies.get(enemyNum);
        if (enemy.hitbox().intersects(player.hitbox())) {
          player.combatChange(true);
          enemy.combatChange(true);
          battleBegin();
        }
      }
    } else if (scene == BATTLE) {
      if (keyID == KeyEvent.VK_SPACE
          && player.getStamina() >= 33.3
          && !player.getDeath()
          && !battleWon) {
        int target = 0;
        spellsThrown.add(
            new Spell(
                0,
                new Color(153, 76, 0),
                player.centerX(),
                player.centerY(),
                enemies.get(target).centerX(),
                enemies.get(target).centerY(),
                target));
        player.staminaGain(-333);
      }
      if (keyID == KeyEvent.VK_ENTER
          && player.getStamina() == 100
          && !player.getDeath()
          && !battleWon) {
        int target = 0;
        spellsThrown.add(
            new Spell(
                1,
                Color.LIGHT_GRAY,
                player.centerX(),
                player.centerY(),
                enemies.get(target).centerX(),
                enemies.get(target).centerY(),
                target));
        player.staminaGain(-1000);
      }
      if ((keyID == KeyEvent.VK_ENTER || keyID == KeyEvent.VK_SPACE) && battleWon) {
        if (player.levelUp()) {
          nextWindow = true;
        } else {
          battleEnd();
        }
      }
    }
    repaint();
  }