コード例 #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
 public void checkAllyPresence() {
   if (scene == BATTLE) {
     // int loop;
     int deadCounter = 0;
     if (player.getDeath()) deadCounter++;
     /*for (loop = 0; loop < allies.size(); loop++){
     	if (allies.get(loop).getDeath())
     		deadCounter++;
     }*/
     if (deadCounter == allies.size() + 1) defeat();
   }
 }
コード例 #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();
  }