Exemple #1
0
 public final void addAmmo(int amount, Class weaponType) {
   for (Weapon w : weapons) {
     if (w.getClass().equals(weaponType)) {
       w.addAmmo(amount);
     }
   }
 }
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 void setFiring(boolean firing) {
   if (this.firing == firing) {
     return;
   } else {
     this.firing = firing;
     if (!firing) {
       weapon.c**k();
     }
   }
 }
Exemple #4
0
  @Override
  public void update() {
    if (autoPilot.getStatus() == AutoPilot.SystemStatus.ON) {
      autoPilot.update();
    }

    switch (rotation) {
      case RIGHT:
        direction.x = (direction.x * cos) - (direction.y * sin);
        direction.y = (direction.x * sin) + (direction.y * cos);
        break;
      case LEFT:
        direction.x = (direction.x * cos) + (direction.y * sin);
        direction.y = -(direction.x * sin) + (direction.y * cos);
        break;
    }

    direction = direction.direction();

    if (boosting) {
      vel.add(direction);

      vel.x = (Math.abs(vel.x) > 35) ? Math.signum(vel.x) * 35 : vel.x;
      vel.y = (Math.abs(vel.y) > 35) ? Math.signum(vel.y) * 35 : vel.y;
    } else if (breaking) {
      slow();
    }

    pos.x += vel.x;
    pos.y += vel.y;
    rectangle.setLocation(pos.getPoint());

    // bounds checking:
    if (pos.x < 0) {
      pos.x = ViewFrame.size.width - 1;
    } else if (pos.x > ViewFrame.size.width - 1) {
      pos.x = 0;
    }

    if (pos.y < 0) {
      pos.y = ViewFrame.size.height - 1;
    } else if (pos.y > ViewFrame.size.height - 1) {
      pos.y = 0;
    }

    if (firing) {
      weapon.fire();
      displayAmmo();
    }
  }
Exemple #5
0
 public final void setWeapon(int weaponIndex) {
   weapon = weapons.get(weaponIndex);
   ViewFrame.getInstance().setWeapon(weapon.toString());
 }
Exemple #6
0
 private void displayAmmo() {
   ViewFrame.getInstance().setAmmo(weapon.getRounds(), weapon.getClipSize(), weapon.getAmmo());
 }
Exemple #7
0
 public final void reload() {
   if (weapon.getAmmo() > 0) {
     weapon.reload();
     displayAmmo();
   }
 }