@Override
  public void start(Scene scene) {
    database = new SpatialArray<Vec2>(32);

    newSprite(
        Color.red,
        15,
        190,
        new SteerSet<Vec2>(
            new SteerTo<Vec2>(
                500,
                slowest =
                    new TargetSlowest<Vec2>(
                        database,
                        null,
                        100,
                        200,
                        false,
                        32,
                        SpatialDatabase.ALL_GROUPS,
                        Vec2.FACTORY)),
            new SteerWander2(500, 0, 100, 150, 80)));

    for (int i = 0; i < 24; i++) {
      SteerSprite lamb =
          newSprite(
              Color.white,
              10,
              SteerMath.randomFloat(150, 250),
              new SteerWander2(1000, 0, 100, 150, 80));
      lamb.position.set(SteerMath.randomFloat(width), SteerMath.randomFloat(height));
      database.add(lamb);
    }
  }
Esempio n. 2
0
  @Override
  public V getTarget(SteerSubject<V> s) {
    subject = s;
    slowestVelocitySq = Float.MAX_VALUE;

    queryPosition.set(subject.getPosition());
    queryPosition.addsi(subject.getDirection(), queryOffset);

    int found = 0;

    if (contains) {
      found = space.contains(queryPosition, queryRadius, max, groups, this);
    } else {
      found = space.intersects(queryPosition, queryRadius, max, groups, this);
    }

    if (found == 0) {
      return null;
    }

    return target;
  }