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

项目:0Bit-Engine    文件:SteeringEntity.java   
public void update(float deltaTime) {
    if (steeringBehavior != null && mvc != null) {
        boolean applySteering = true;
        steeringBehavior.calculateSteering(steeringOutput);

        mvc.right = false;
        mvc.left = false;
        if (!(getSteeringBehavior() instanceof Seek)) {
            // TODO: Move to behaviour and track back to patrol area
            if (minX != null && steeringOutput.linear.x < 0 && getPosition().x - 0.1 < minX) applySteering = false;
            else if (maxX != null && steeringOutput.linear.x > 0 && getPosition().x + 0.1 > maxX)
                applySteering = false;
        }
        if (applySteering) {
            applySteering(steeringOutput, deltaTime);
        } else {
            stop();
        }
    }
}
项目:0Bit-Engine    文件:EnemyController.java   
@Override
public boolean reportNeighbourBody(Body neighbor) {
    if (((Box2DUserData)neighbor.getUserData()).id.equals("")) { //TODO: Check from target array
        if (!(steerable.getSteeringBehavior() instanceof Seek)) {
            steerable.setSteeringBehavior(new Seek<Vector2>(steerable, new SteeringEntity(neighbor, 1f)));
            steerable.setMaxLinearSpeed(chaseSpeed);
        }
        else if (((SteeringEntity)((Seek)steerable.getSteeringBehavior()).getTarget()).getBody() != neighbor) {
            steerable.setSteeringBehavior(new Seek<Vector2>(steerable, new SteeringEntity(neighbor, 1f)));
            steerable.setMaxLinearSpeed(chaseSpeed);
        }

        // Attack!
        ((Box2DUserData)steerable.getBody().getUserData()).stateComponent.state = EntityStates.ATTACKING_RANGED;

        return true;
    }
    return false;
}
项目:gdxjam-ugg    文件:EnemySeekConfig.java   
@Override
public void applyConfigs(SteeringBehaviorComponent steeringBC) {
    Seek seek = (Seek)steeringBC.behavior;
    Steerable steerable = seek.getOwner();
    steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED);
    steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION);
    steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED);
    steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION);

}
项目:gdxjam-ugg    文件:BehaviorUtils.java   
public static SteerLocation getTarget(SteeringBehavior behavior){
    SteerLocation targetL = null;
    if(behavior instanceof Face) targetL = (SteerLocation)((Face) behavior).getTarget();
    else if(behavior instanceof Arrive) targetL = (SteerLocation)((Arrive) behavior).getTarget();
    else if(behavior instanceof Seek) targetL = (SteerLocation)((Seek) behavior).getTarget();
    return targetL;
}
项目:JACWfA    文件:scSeek.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);
    Seek<Vector2> sb = new Seek<Vector2>(Ann, Bob);
    Ann.setSteeringBehavior(sb);
}
项目:gdx-ai    文件:Box2dSeekTest.java   
@Override
public void create () {
    super.create();

    spriteBatch = new SpriteBatch();

    // Create character
    character = createSteeringEntity(world, container.greenFish);
    character.setMaxLinearSpeed(5);
    character.setMaxLinearAcceleration(10);

    // Create target
    target = createSteeringEntity(world, container.target);
    markAsSensor(target);
    inputProcessor = new Box2dTargetInputProcessor(target);

    // Create character's steering behavior
    final Seek<Vector2> seekSB = new Seek<Vector2>(character, target);
    character.setSteeringBehavior(seekSB);

    Table detailTable = new Table(container.skin);

    detailTable.row();
    addMaxLinearAccelerationController(detailTable, character, 0, 200, 1);

    detailTable.row();
    addSeparator(detailTable);

    detailTable.row();
    addMaxLinearSpeedController(detailTable, character, 0, 30, .5f);

    detailWindow = createDetailWindow(detailTable);
}
项目:gdx-ai    文件:Scene2dSeekTest.java   
@Override
public void create () {
    super.create();

    character = new SteeringActor(container.badlogicSmall, false);
    target = new SteeringActor(container.target);
    inputProcessor = new Scene2dTargetInputProcessor(target);

    character.setMaxLinearSpeed(250);
    character.setMaxLinearAcceleration(2000);

    final Seek<Vector2> seekSB = new Seek<Vector2>(character, target);
    character.setSteeringBehavior(seekSB);

    testTable.addActor(character);
    testTable.addActor(target);

    character.setPosition(container.stageWidth / 2, container.stageHeight / 2, Align.center);
    target.setPosition(MathUtils.random(container.stageWidth), MathUtils.random(container.stageHeight), Align.center);

    Table detailTable = new Table(container.skin);

    detailTable.row();
    addMaxLinearAccelerationController(detailTable, character, 0, 10000, 20);

    detailTable.row();
    addSeparator(detailTable);

    detailTable.row();
    addMaxLinearSpeedController(detailTable, character);

    detailWindow = createDetailWindow(detailTable);
}
项目:gdx-ai    文件:BulletSeekTest.java   
@Override
public void create () {
    super.create();

    BulletEntity ground = world.add("ground", 0f, 0f, 0f);
    ground.setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
        0.25f + 0.5f * (float)Math.random(), 1f);
    ground.body.userData = "ground";

    BulletEntity characterBase = world.add("capsule", new Matrix4());

    character = new SteeringBulletEntity(characterBase);
    character.setMaxLinearSpeed(50);
    character.setMaxLinearAcceleration(200);

    BulletEntity targetBase = world.add("staticbox", new Matrix4().setToTranslation(new Vector3(5f, 1.5f, 5f)));
    targetBase.body.setCollisionFlags(targetBase.body.getCollisionFlags()
        | btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE);
    target = new SteeringBulletEntity(targetBase);

    setNewTargetInputProcessor(target, new Vector3(0, 1.5f, 0));

    final Seek<Vector3> seekSB = new Seek<Vector3>(character, target);
    character.setSteeringBehavior(seekSB);

    Table detailTable = new Table(container.skin);

    detailTable.row();
    addMaxLinearAccelerationController(detailTable, character, 0, 2000, 100);

    detailTable.row();
    addSeparator(detailTable);

    detailTable.row();
    addMaxLinearSpeedController(detailTable, character, 0, 200, 1);

    detailWindow = createDetailWindow(detailTable);
}