Exemple #1
0
 public final void damage(int amount) {
   shields -= amount;
   if (shields < 0) shields = 0;
   wasHit = true;
   if (shields < 50) {
     autoPilot.setStatus(AutoPilot.SystemStatus.DAMAGED);
   }
   ViewFrame.getInstance().setHealth(shields);
 }
Exemple #2
0
 public final void cycleWeapon(int direction) {
   do {
     weaponIndex += direction;
     if (weaponIndex < 0) {
       weaponIndex = weapons.size() - 1;
     } else if (weaponIndex >= weapons.size()) {
       weaponIndex = 0;
     }
     weapon = weapons.get(weaponIndex);
   } while (weapon.getAmmo() + weapon.getRounds() == 0);
   ViewFrame.getInstance().setWeapon(weapon.toString());
   displayAmmo();
 }
Exemple #3
0
  public final GameObject cycleTarget(boolean enemyFirst) {

    Game game = ViewFrame.getInstance().getGame();
    if (enemyFirst) {
      target = game.getEnemy();
      if (target != null) {
        return target;
      } else {
        target = game.getItem();
      }
    } else {
      target = game.getItem();
      if (target != null) {
        return target;
      } else {
        target = game.getEnemy();
      }
    }
    return target;
  }
Exemple #4
0
 public final void setWeapon(int weaponIndex) {
   weapon = weapons.get(weaponIndex);
   ViewFrame.getInstance().setWeapon(weapon.toString());
 }
Exemple #5
0
  public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_P) {
      ViewFrame.getInstance().pause();
      return;
    } else if (keyCode == KeyEvent.VK_A) {

      SystemStatus status = autoPilot.getStatus();
      switch (status) {
        case ON:
          autoPilot.setStatus(AutoPilot.SystemStatus.OFF);
          boosting = firing = false;
          rotation = Rotation.NONE;
          break;
        case OFF:
          autoPilot.setStatus(AutoPilot.SystemStatus.ON);
          break;
        default:
          return;
      }
      return;
    }

    if (autoPilot.getStatus() == AutoPilot.SystemStatus.ON) {
      return;
    }

    switch (keyCode) {
      case KeyEvent.VK_UP:
        {
          if (!boosting) {
            setBoosting(true);
          }
          break;
        }
      case KeyEvent.VK_DOWN:
        {
          if (!breaking) {
            setBreaking(true);
          }
          break;
        }
      case KeyEvent.VK_LEFT:
        {
          setRotation(Player.Rotation.LEFT);
          break;
        }
      case KeyEvent.VK_RIGHT:
        {
          setRotation(Player.Rotation.RIGHT);
          break;
        }
      case KeyEvent.VK_D:
        {
          cycleTarget(true);
          break;
        }
      case KeyEvent.VK_Q:
        {
          cycleWeapon(-1);
          break;
        }
      case KeyEvent.VK_E:
        {
          cycleWeapon(1);
          break;
        }
      case KeyEvent.VK_SPACE:
        firing = true;
        break;
      case KeyEvent.VK_R:
        reload();
        break;
    }
  }
Exemple #6
0
 private void displayAmmo() {
   ViewFrame.getInstance().setAmmo(weapon.getRounds(), weapon.getClipSize(), weapon.getAmmo());
 }