Ejemplo 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);
    }
  }
Ejemplo n.º 2
-1
  private void doShooting() {
    PositionFinder p = new PositionFinder(enemies, this);
    en = p.findNearest();
    if (en == null) return;

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

    if (HoT) {
      /* Perform head on target for gun movement */
      aimingPoint = new Point2D.Double(en.getX(), en.getY());
      double turnGunAmt = (getHeadingRadians() + en.getBearingRadians() - getGunHeadingRadians());
      turnGunAmt = Utils.normalRelativeAngle(turnGunAmt);
      setTurnGunRightRadians(turnGunAmt);
    } else {
      /* Perform circular targeting */
      Rectangle2D battlefield =
          new Rectangle2D.Double(0, 0, getBattleFieldWidth(), getBattleFieldHeight());
      long when = calcTimeToReachEnemy();
      aimingPoint = org.pattern.utils.Utils.getFuturePoint(en, when);
      if (!battlefield.contains(aimingPoint)) {
        HoT = true;
        return;
      }
      double theta =
          Utils.normalAbsoluteAngle(
              Math.atan2(aimingPoint.getX() - getX(), aimingPoint.getY() - getY()));
      setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
    }

    if (getGunHeat() == 0) {
      double firePower = 3.0;
      fire(firePower);
    }
  }