Esempio n. 1
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();
    }
  }