com.badlogic.gdx.ai.steer.behaviors.Wander Java Examples
The following examples show how to use
com.badlogic.gdx.ai.steer.behaviors.Wander.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WanderSteerer.java From GdxDemo3D with Apache License 2.0 | 6 votes |
public WanderSteerer(final SteerableBody steerableBody) { super(steerableBody); this.wanderSB = new Wander<Vector3>(steerableBody) { @Override protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) { super.calculateRealSteering(steering); steering.linear.y = 0; // remove any vertical acceleration return steering; } }; this.wanderSB.setWanderOffset(8) // .setWanderOrientation(0) // .setWanderRadius(0.5f) // .setWanderRate(MathUtils.PI2 * 4); this.prioritySteering.add(wanderSB); }
Example #2
Source File: GhostAI.java From Pacman_libGdx with MIT License | 4 votes |
private void createWanderBehavior() { wanderBehavior = new Wander<>(this) .setEnabled(true) .setWanderRadius(2f) .setWanderRate(MathUtils.PI2 * 4); }
Example #3
Source File: Scene2dPursueTest.java From gdx-ai with Apache License 2.0 | 4 votes |
@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); }
Example #4
Source File: ParallelVsSequenceTest.java From gdx-ai with Apache License 2.0 | 4 votes |
public TestScreen (final ParallelVsSequenceTest test, Skin skin) { this.test = test; this.skin = skin; lastUpdateTime = 0; gameOver = false; greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png")); badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg")); targetTextureRegion = new TextureRegion(new Texture("data/target.png")); shapeRenderer = new ShapeRenderer(); stage = new Stage(); Stack testStack = new Stack(); stage.addActor(testStack); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stage.getWidth(), stage.getHeight()); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(new IntValueLabel("Sequence (Fish): ", 0, skin) { @Override public int getValue () { return sequencePredator.score; } }).padLeft(15); statusBar.add(new IntValueLabel("Parallel (Badlogics): ", 0, skin) { @Override public int getValue () { return parallelPredator.score; } }).padLeft(15); stage.addActor(statusBar); // Add test table testStack.setSize(stage.getWidth(), stage.getHeight()); testStack.add(testTable = new Table() { @Override public void act (float delta) { float time = GdxAI.getTimepiece().getTime(); if (lastUpdateTime != time) { lastUpdateTime = time; super.act(GdxAI.getTimepiece().getDeltaTime()); } } }); testStack.layout(); this.sheeps = new Array<Sheep>(); for (int i = 0; i < 30; i++) { Sheep sheep = new Sheep(targetTextureRegion); sheep.setMaxLinearAcceleration(50); sheep.setMaxLinearSpeed(80); sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled sheep.setMaxAngularSpeed(5); Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) // .setFaceEnabled(true) // 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(90) // .setWanderOrientation(10) // .setWanderRadius(40) // .setWanderRate(MathUtils.PI2 * 4); sheep.setSteeringBehavior(wanderSB); setRandomNonOverlappingPosition(sheep, sheeps, 5); setRandomOrientation(sheep); testTable.addActor(sheep); sheeps.add(sheep); } sequencePredator = createPredator(false); parallelPredator = createPredator(true); // Create GameOver panel gameOverButton = new TextButton("Game Over", skin); gameOverButton.setVisible(false); gameOverButton.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { test.backToPreviousScreen(); } }); testTable.add(gameOverButton); }
Example #5
Source File: ResumeVsJoinTest.java From gdx-ai with Apache License 2.0 | 4 votes |
public TestScreen (final ResumeVsJoinTest test, Skin skin) { this.test = test; this.skin = skin; lastUpdateTime = 0; gameOver = false; greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png")); badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg")); targetTextureRegion = new TextureRegion(new Texture("data/target.png")); shapeRenderer = new ShapeRenderer(); stage = new Stage(); Stack testStack = new Stack(); stage.addActor(testStack); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stage.getWidth(), stage.getHeight()); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(new IntValueLabel("Resume (Fish): ", 0, skin) { @Override public int getValue () { return resumePredator.score; } }).padLeft(15); statusBar.add(new IntValueLabel("Join (Badlogics): ", 0, skin) { @Override public int getValue () { return joinPredator.score; } }).padLeft(15); stage.addActor(statusBar); // Add test table testStack.setSize(stage.getWidth(), stage.getHeight()); testStack.add(testTable = new Table() { @Override public void act (float delta) { float time = GdxAI.getTimepiece().getTime(); if (lastUpdateTime != time) { lastUpdateTime = time; super.act(GdxAI.getTimepiece().getDeltaTime()); } } }); testStack.layout(); this.sheeps = new Array<Sheep>(); for (int i = 0; i < 30; i++) { Sheep sheep = new Sheep(targetTextureRegion); sheep.setMaxLinearAcceleration(50); sheep.setMaxLinearSpeed(80); sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled sheep.setMaxAngularSpeed(5); Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) // .setFaceEnabled(true) // 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(90) // .setWanderOrientation(10) // .setWanderRadius(40) // .setWanderRate(MathUtils.PI2 * 4); sheep.setSteeringBehavior(wanderSB); setRandomNonOverlappingPosition(sheep, sheeps, 5); setRandomOrientation(sheep); testTable.addActor(sheep); sheeps.add(sheep); } resumePredator = createPredator(false); joinPredator = createPredator(true); // Create GameOver panel gameOverButton = new TextButton("Game Over", skin); gameOverButton.setVisible(false); gameOverButton.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { test.backToPreviousScreen(); } }); testTable.add(gameOverButton); }