Ejemplo n.º 1
0
  private void try_transition(Dir dir) {
    // No transition yet.
    if (percentage < 1 - straight_per_inc) {
      return;
    }

    TrackPiece newLocation = null;

    switch (dir) {
      case LEFT:
        newLocation = myLocation.getLeft();
        break;
      case UP:
        newLocation = myLocation.getUp();
        break;
      case DOWN:
        newLocation = myLocation.getDown();
        break;
      case RIGHT:
        newLocation = myLocation.getRight();
        break;
    }

    if (newLocation == null) {
      handle_end_of_track();
    } else {
      myLocation = newLocation;
      percentage = 0;

      // Make sure we keep track of which direction the car is currently going in.
      myDir = dir;
    }
  }
Ejemplo n.º 2
0
  private void handle_down_straight() {
    percentage += straight_per_inc;

    angle = 90;

    x = myLocation.x + myLocation.getW() / 2;
    y = myLocation.y + (int) (myLocation.getH() * percentage);

    try_transition(Dir.DOWN);
  }
Ejemplo n.º 3
0
  private void handle_left_straight() {
    percentage += straight_per_inc;

    angle = 0;

    x = myLocation.x + myLocation.getW() - (int) (myLocation.getH() * percentage);
    y = myLocation.y + myLocation.getH() / 2;

    try_transition(Dir.LEFT);
  }
Ejemplo n.º 4
0
  // Sets the location of this car.
  // We will assume that cars start on a right facing straight segment of track.
  public void setLocation(TrackPiece track) {
    myLocation = track;

    moving = true;

    x = myLocation.x + myLocation.getW() / 2;
    y = myLocation.y + myLocation.getH() / 2;

    percentage = .5;
    angle = 0; // Starts facing right.
  }
Ejemplo n.º 5
0
  private void handle_down_curve_right() {
    percentage += curve_per_inc;

    int radius = myLocation.getW() * 3 / 4;

    angle = (int) (90 - 90 * percentage);

    // Angle along the curve.
    double theta = Math.toRadians(90 * percentage);

    x = (int) (myLocation.x + myLocation.getW() - radius * Math.cos(theta));
    y = (int) (myLocation.y + radius * Math.sin(theta));

    try_transition(Dir.RIGHT);
  }