Exemplo n.º 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);
       }
     }
   }
 }
Exemplo n.º 2
0
  public void actionPerformed(ActionEvent a) {
    Object source = a.getSource();

    if (scene == OVERWORLD) {
      if (source == moveTimer) {
        if (moveUp && !moveDown) player.moveUp();
        else if (!moveUp && moveDown) player.moveDown();

        if (moveLeft && !moveRight) player.moveLeft();
        else if (!moveLeft && moveRight) player.moveRight();
      }

      if (source == itemsButton) itemsButton.setText("ITEMS!");
      else if (source == equipButton) equipButton.setText("EQUIPMENT!");
      else if (source == skillsButton) skillsButton.setText("SKILLS");
      else if (source == settingsButton) settingsButton.setText("SETTINGS");
      else if (source == statusButton) statusButton.setText("STATUS");
      else if (source == dataButton) dataButton.setText("DATA");
    }
    if (scene == BATTLE) {
      if (source == moveTimer) {
        // Spell Movement
        for (int spellNum = 0; spellNum < spellsThrown.size(); spellNum++) {
          Spell spell = spellsThrown.get(spellNum);
          spell.move();
          if (spell.spellHit()) {
            enemies.get(spell.getTarget()).takeDamage(spell.getDamage());
            enemies.get(spell.getTarget()).statusPresent(spell.getEffect());
            spellsThrown.remove(spellNum);
            checkEnemyPresence();
          }
        }

        for (int enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          Enemy enemy = enemies.get(enemyLoop);
          for (int spellNum = 0; spellNum < enemy.spellsThrown.size(); spellNum++) {
            Spell spell = enemy.spellsThrown.get(spellNum);
            spell.move();
            if (spell.spellHit()) {
              player.takeDamage(spell.getDamage());
              enemy.spellsThrown.remove(spellNum);
              checkAllyPresence();
            }
          }
        }
      }
      if (source == staminaTimer) {
        // Stamina Regeneration
        player.staminaGain(16);
        // Enemy Attacks
        int enemyLoop;
        for (enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          enemies.get(enemyLoop).attack(player.centerX(), player.centerY(), 12);
        }
      }
    }
    repaint();

    // To check collision
    if (scene == OVERWORLD) {
      for (int loop = 0; loop < enemies.size(); loop++) {
        Enemy enemy = enemies.get(loop);
        if (enemy.hitbox().intersects(player.hitbox())) {
          player.combatChange(true);
          enemy.combatChange(true);
          battleBegin();
        }
      }
    }
  }
Exemplo n.º 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();
  }