Exemplo n.º 1
0
  private void gotoPointandSmooth() {

    Point2D actualPosition = new Point2D.Double(getX(), getY());

    Projection proj =
        new Projection(
            new Point2D.Double(getX(), getY()),
            getHeading(),
            getVelocity(),
            move.ahead,
            getTurnRemaining() + move.turnRight);
    tickProjection t = proj.projectNextTick();

    /* Movement Settings, find the next position */
    double distanceToNewPosition = actualPosition.distance(nextPosition);
    if (move.smooth(t.getPosition(), t.getHeading(), proj.getWantedHeading(), move.ahead)) {
      // out.println("smooth");
      wallSmoothing = true;
      double _turnRight = move.turnRight;
      int _ahead = 100 * move.ahead;

      setAhead(_ahead);
      setTurnRight(_turnRight);
    } else if (distanceToNewPosition < 15 || wallSmoothing == true) {
      wallSmoothing = false;
      PositionFinder p = new PositionFinder(enemies, this);
      // Point2D.Double testPoint = p.findBestPoint(200);
      // double range = distanceToTarget*0.5;
      // Point2D.Double testPoint = p.findBestPointInRange(attempt, range);
      Point2D.Double testPoint = p.findBestPointInRangeWithRandomOffset(200);
      nextPosition = testPoint;
      // out.println("point");
    }

    /* Movement to nextPosition */
    else {
      Double angle =
          org.pattern.utils.Utils.calcAngle(nextPosition, actualPosition) - getHeadingRadians();
      Double direction = 1.0;

      if (Math.cos(angle) < 0) {
        angle += Math.PI;
        direction = -1.0;
      }
      if (direction > 0) move.ahead = 1;
      else move.ahead = -1;
      setAhead(distanceToNewPosition * direction);
      angle = Utils.normalRelativeAngle(angle);
      setTurnRightRadians(angle);
    }
  }
Exemplo n.º 2
0
  private void goToPoint(Point2D nextPosition) {

    Point2D actualPosition = new Point2D.Double(getX(), getY());
    Double distanceToNewPosition = actualPosition.distance(nextPosition);
    Double angle =
        org.pattern.utils.Utils.calcAngle(nextPosition, actualPosition) - getHeadingRadians();
    Double direction = 1.0;

    if (Math.cos(angle) < 0) {
      angle += Math.PI;
      direction = -1.0;
    }
    if (direction > 0) move.ahead = 1;
    else move.ahead = -1;
    setAhead(distanceToNewPosition * direction);
    angle = Utils.normalRelativeAngle(angle);
    setTurnRightRadians(angle);
  }