コード例 #1
0
ファイル: Player.java プロジェクト: ylegall/Prototype
 public final void addShields(int amount) {
   shields += amount;
   if (shields > 255) shields = 255;
   else if (shields > 50) {
     if (autoPilot.getStatus() == AutoPilot.SystemStatus.DAMAGED) {
       autoPilot.setStatus(AutoPilot.SystemStatus.OFF);
     }
   }
 }
コード例 #2
0
ファイル: Player.java プロジェクト: ylegall/Prototype
  @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();
    }
  }
コード例 #3
0
ファイル: Player.java プロジェクト: ylegall/Prototype
 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);
 }
コード例 #4
0
ファイル: Player.java プロジェクト: ylegall/Prototype
  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;
    }
  }