private Predator createPredator (boolean parallel) { Predator predator = new Predator(parallel ? badlogicTextureRegion : greenFishTextureRegion, this); predator.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()), Align.center); predator.setMaxLinearSpeed(100); predator.setMaxLinearAcceleration(600); final Pursue<Vector2> pursueSB = new Pursue<Vector2>(predator, null, .5f); predator.setSteeringBehavior(pursueSB); testTable.addActor(predator); BranchTask<Predator> branch = parallel ? new Parallel<Predator>() : new Sequence<Predator>(); branch.addChild(new SelectTargetTask()); branch.addChild(new PursueTask()); predator.btree = new BehaviorTree<Predator>(branch, predator); return predator; }
@Override public Status execute () { Predator predator = getObject(); boolean success = false; if (predator.target != null) { success = predator.canEatTarget(); if (success) predator.eatTarget(); else if (!predator.target.eaten) { ((Pursue)predator.getSteeringBehavior()).setEnabled(true); ((Pursue)predator.getSteeringBehavior()).setTarget(predator.target); return Status.RUNNING; } } ((Pursue)predator.getSteeringBehavior()).setEnabled(false); return success ? Status.SUCCEEDED : Status.FAILED; }
private Predator createPredator (boolean join) { Predator predator = new Predator(join ? badlogicTextureRegion : greenFishTextureRegion, this); predator.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()), Align.center); predator.setMaxLinearSpeed(100); predator.setMaxLinearAcceleration(600); final Pursue<Vector2> pursueSB = new Pursue<Vector2>(predator, null, .5f); predator.setSteeringBehavior(pursueSB); testTable.addActor(predator); BranchTask<Predator> branch = join ? new Parallel<Predator>(Orchestrator.Join) : new Parallel<Predator>(Orchestrator.Resume); branch.addChild(new SpinAroundTask()); branch.addChild(new SelectTargetTask()); branch.addChild(new PursueTask()); predator.btree = new BehaviorTree<Predator>(branch, predator); return predator; }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Pursue pursue = (Pursue)steeringBC.behavior; Steerable steerable = pursue.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); pursue.setMaxPredictionTime(0.85f); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Pursue pursue = (Pursue)steeringBC.behavior; Steerable steerable = pursue.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); }
@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); Bob.linearVelocity = new Vector2(50, -50); Pursue<Vector2> sb = new Pursue<Vector2>(Ann, Bob); Ann.setSteeringBehavior(sb); }
public void selectTarget () { target = null; ((Pursue)getSteeringBehavior()).setTarget(null); Vector2 pos = getPosition(); float minDist = Float.POSITIVE_INFINITY; for (Sheep sheep : testScreen.sheeps) { float dist = sheep.getPosition().dst2(pos); if (dist < minDist) { minDist = dist; target = sheep; } } }
@Override public void create () { super.create(); character = new SteeringActor(container.badlogicSmall, false); character.setPosition(MathUtils.random(container.stageWidth), MathUtils.random(container.stageHeight), Align.center); character.setMaxLinearSpeed(100); character.setMaxLinearAcceleration(600); prey = new SteeringActor(container.target, false); prey.setPosition(MathUtils.random(container.stageWidth), MathUtils.random(container.stageHeight), Align.center); prey.setMaxLinearSpeed(100); prey.setMaxLinearAcceleration(250); prey.setMaxAngularAcceleration(0); // used by Wander; set to 0 because independent facing is disabled prey.setMaxAngularSpeed(5); final Pursue<Vector2> pursueSB = new Pursue<Vector2>(character, prey, 0.3f); character.setSteeringBehavior(pursueSB); Wander<Vector2> wanderSB = new Wander<Vector2>(prey) // // Don't use Face internally because independent facing is off .setFaceEnabled(false) // // No need to call setAlignTolerance, setDecelerationRadius and setTimeToTarget for the same reason .setWanderOffset(110) // .setWanderOrientation(10) // .setWanderRadius(64) // .setWanderRate(MathUtils.PI2 * 3.5f); prey.setSteeringBehavior(wanderSB); testTable.addActor(character); testTable.addActor(prey); Table detailTable = new Table(container.skin); detailTable.row(); addMaxLinearAccelerationController(detailTable, character, 0, 2000, 20); detailTable.row(); final Label labelMaxPredictionTime = new Label("Max.Prediction Time[" + pursueSB.getMaxPredictionTime() + "] sec.", container.skin); detailTable.add(labelMaxPredictionTime); detailTable.row(); Slider maxPredictionTime = new Slider(0, 5, .1f, false, container.skin); maxPredictionTime.setValue(pursueSB.getMaxPredictionTime()); maxPredictionTime.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { Slider slider = (Slider)actor; pursueSB.setMaxPredictionTime(slider.getValue()); labelMaxPredictionTime.setText("Max.Prediction Time [" + slider.getValue() + "] sec."); } }); detailTable.add(maxPredictionTime); detailTable.row(); addSeparator(detailTable); detailTable.row(); addMaxLinearSpeedController(detailTable, character, 0, 300, 10); detailWindow = createDetailWindow(detailTable); }