Example usage for com.badlogic.gdx.ai.steer.behaviors PrioritySteering add

List of usage examples for com.badlogic.gdx.ai.steer.behaviors PrioritySteering add

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.steer.behaviors PrioritySteering add.

Prototype

public PrioritySteering<T> add(SteeringBehavior<T> behavior) 

Source Link

Document

Adds the specified behavior to the priority list.

Usage

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public void wander() {

    // Set wandering
    PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
    RaycastCollisionDetector<Vector2> raycastCollisionDetector = new CreatureRayCastCollisionDetector(
            worldState);//  ww w.ja  v  a2 s .  c om
    RaycastObstacleAvoidance<Vector2> raycastObstacleAvoidanceSB = new RaycastObstacleAvoidance<>(this,
            new SingleRayConfiguration<>(this, 1.5f), raycastCollisionDetector, 0.5f);
    prioritySteering.add(raycastObstacleAvoidanceSB);
    prioritySteering.add(new Wander<>(this).setFaceEnabled(false) // We want to use Face internally (independent facing is on)
            .setAlignTolerance(0.001f) // Used by Face
            .setDecelerationRadius(5) // Used by Face
            .setTimeToTarget(0.1f) // Used by Face
            .setWanderOffset(10) //
            .setWanderOrientation(10) //
            .setWanderRadius(10) //
            .setWanderRate(FastMath.TWO_PI * 4));
    setSteeringBehavior(prioritySteering);
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public void navigateToRandomPoint() {
    Point p = worldState.findRandomAccessibleTile(
            worldState.getTileCoordinates(getSpatial().getWorldTranslation()), 10, creature);
    if (p != null) {
        GraphPath<TileData> outPath = worldState
                .findPath(worldState.getTileCoordinates(getSpatial().getWorldTranslation()), p, creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }// w w  w .jav  a 2s  .c om
    }
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public void navigateToAssignedTask() {

    Vector2f loc = assignedTask.getTarget(this);
    if (loc != null) {
        GraphPath<TileData> outPath = worldState.findPath(
                worldState.getTileCoordinates(getSpatial().getWorldTranslation()),
                new Point((int) Math.floor(loc.x), (int) Math.floor(loc.y)), creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }// www  .ja  v  a  2s . com
    }
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

/**
 * Set follow mode/*from  ww w . j  a  v  a  2  s.c o m*/
 *
 * @param target the target to follow
 * @return true if it is valid to follow it
 */
public boolean followTarget(CreatureControl target) {
    if (target != null) {
        followTarget = target;
        PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);

        // Create proximity
        Array<CreatureControl> creatures;
        if (party != null) {
            creatures = new Array<>(party.getActualMembers().size());
            for (CreatureControl cr : party.getActualMembers()) {
                creatures.add(cr);
            }
        } else {
            creatures = new Array<>(2);
            creatures.add(target);
            creatures.add(this);
        }

        // Hmm, proximity should be the same instance? Gotten from the party?
        Cohesion<Vector2> cohersion = new Cohesion<>(this, new InfiniteProximity<Vector2>(this, creatures));
        prioritySteering.add(cohersion);

        setSteeringBehavior(prioritySteering);
        return true;
    }
    return false;
}