Java 类com.badlogic.gdx.ai.steer.behaviors.BlendedSteering 实例源码

项目:JACWfA    文件:scBlended.java   
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
    super.init(config);
    Ann = new Agent(new Vector2(0, 0), 0);
    Bob = new Agent(new Vector2(10000, 0), 0);

    Arrive<Vector2> aSB = new Arrive<Vector2>(Ann, Bob);
    LookWhereYouAreGoing<Vector2> lwyagSB = new LookWhereYouAreGoing<Vector2>(
            Ann);

    BlendedSteering<Vector2> sb = new BlendedSteering<Vector2>(Ann)
            .setLimiter(NullLimiter.NEUTRAL_LIMITER).add(aSB, 1f)
            .add(lwyagSB, 1f);

    Ann.setSteeringBehavior(sb);
}
项目:GDXJam    文件:EntityFactory.java   
public static Entity createSquad (Vector2 position, Faction faction) {
    Entity entity = builder.createEntity(EntityCategory.SQUAD, position).physicsBody(BodyType.DynamicBody).circleSensor(30.0f)
        .faction(faction).target().filter(EntityCategory.SQUAD, 0, EntityCategory.SQUAD | EntityCategory.RESOURCE)
        .steeringBehavior().stateMachine().getWithoutAdding();

    SteerableComponent steerable = engine.createComponent(SteerableComponent.class).init(
        Components.PHYSICS.get(entity).getBody(), 30.0f);
    SquadComponent squadComp = engine.createComponent(SquadComponent.class).init(steerable);
    squadComp.targetLocation.getPosition().set(position);
    entity.add(squadComp);

    // A good rule of thumb is to make the maximum speed of the formation
    // around
    // half that of the members. We also give the anchor point far less
    // acceleration.
    steerable.setMaxLinearSpeed(SteerableComponent.MAX_LINEAR_SPEED / 2);
    steerable.setMaxLinearAcceleration(SteerableComponent.MAX_LINEAR_ACCELERATION / 10);

    Arrive<Vector2> arriveSB = new Arrive<Vector2>(steerable).setTarget(squadComp.targetLocation).setTimeToTarget(0.001f)
        .setDecelerationRadius(2f).setArrivalTolerance(0.0001f);
    SteeringBehavior<Vector2> sb = arriveSB;

    RadiusProximity<Vector2> proximity = new RadiusProximity<Vector2>(steerable, squadComp.friendlyAgents, 3.0f);
    Separation<Vector2> separationSB = new Separation<Vector2>(steerable, proximity);

    BlendedSteering<Vector2> blendedSteering = new BlendedSteering<Vector2>(steerable) //
        .setLimiter(NullLimiter.NEUTRAL_LIMITER) //
        .add(separationSB, 10000f)
        .add(arriveSB, 0.5f);
    sb = blendedSteering;
    Components.FSM.get(entity).changeState(SquadComponent.DEFAULT_STATE);

    Components.STEERING_BEHAVIOR.get(entity).setBehavior(sb);

    entity.add(steerable);

    engine.addEntity(entity);
    return entity;
}