@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); }
public void setBehavior(int behavior) { switch (behavior) { case ARRIVE_BEHAVIOR: if (arriveBehavior == null) { if (GameManager.instance.playerLocation != null) { arriveBehavior = new Arrive<>(this, GameManager.instance.playerLocation) .setEnabled(true) .setTimeToTarget(0.1f) .setArrivalTolerance(0.5f); steeringBehavior = arriveBehavior; } } else { steeringBehavior = arriveBehavior; } break; case WANDER_BEHAVIOR: steeringBehavior = wanderBehavior; default: break; } }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Arrive arrive = (Arrive)steeringBC.behavior; Steerable steerable = arrive.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); arrive.setArrivalTolerance(0.1f); arrive.setDecelerationRadius(0.1f); arrive.setTimeToTarget(0.05f); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Arrive arrive = (Arrive)steeringBC.behavior; Steerable steerable = arrive.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); arrive.setArrivalTolerance(0.5f); arrive.setDecelerationRadius(10f); arrive.setTimeToTarget(0.005f); }
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; }
public static Arrive createArrive(float x, float y, Steerable steerable){ SteerLocation loc = new SteerLocation(); loc.getPosition().set(x, y); Arrive arrive = new Arrive(steerable, loc); arrive.setTarget(loc); arrive.setOwner(steerable); return arrive; }
@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> sb = new Arrive<Vector2>(Ann, Bob); Ann.setSteeringBehavior(sb); }
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; }
@Override public boolean execute() { final Array<Object> args = cma.getArguments(); Player player = (Player) args.get(0); float x = (float) args.get(3); float y = (float) args.get(4); GameEntity gameEntity = player.mainEntity; if(gameEntity.getCurrentState() != MainShipState.Damaged) { boolean hasTarget = false; Array<Body> aabbFound = Box2dUtils.queryAABBInput(x, y); if(aabbFound.size > 0) { for(Body b : aabbFound){ GameEntity abbEntity = (GameEntity) b.getUserData(); GameEntityType entityType = Mappers.gameEntityType.get(abbEntity.entity).type; if(entityType == GameEntityType.Enemy || entityType == GameEntityType.Scenario) { LockOnComponent lockOnComponent = Mappers.lockOn.get(gameEntity.entity); if(lockOnComponent == null) lockOnComponent = gameEntity.addComponent(LockOnComponent.class); lockOnComponent.origin = gameEntity; lockOnComponent.target = abbEntity; gameEntity.changeState(MainShipState.LockOn); hasTarget = true; break; } } } if(!hasTarget){ SteeringBehaviorComponent steeringBC = Mappers.steeringBehavior.get(gameEntity.entity); Steerable steerableC = Mappers.steerable.get(gameEntity.entity); Arrive<Vector2> arrive = (Arrive<Vector2>) gameEntity.getBehavior(Arrive.class); if (arrive == null) { SteerLocation location = new SteerLocation(); arrive = new Arrive<Vector2>(steerableC, location); arrive.setArrivalTolerance(0.5f); arrive.setDecelerationRadius(10f); arrive.setTimeToTarget(0.005f); } arrive.setOwner(steerableC); gameEntity.cacheBehavior(steeringBC.behavior); steeringBC.behavior = arrive; arrive.getTarget().getPosition().set(x, y); gameEntity.changeState(MainShipState.Ready); } } return true; }
public PlayScreen(DarkDay game, SpriteBatch sb) { this.game = game; this.spriteBatch = sb; gamecam = new OrthographicCamera(); stage = new Stage(); Gdx.input.setInputProcessor(stage); conf = new ConfFacade(); conf.initConfs(208, 400, 32, 10); touchpad = conf.getTouchPad(); stage.addActor(touchpad); viewport = new ScreenViewport(gamecam); debugRenderer = new Box2DDebugRenderer(); world = new World(new Vector2(0, 0f), true); builder = new BodyDirector(new DynamicBodyBuilder(world,viewport.getCamera().viewportWidth / 2 + 3, viewport.getCamera().viewportHeight /2 + 3, 32f , 32f, 1.0f, false )); builder.setBuilder(); entity = new B2dSteeringEntity(builder.getBody(), 10); builder = new BodyDirector(new DynamicBodyBuilder(world, viewport.getCamera().viewportWidth / 2, viewport.getCamera().viewportHeight /2, 32f , 32f, 1.0f, true)); builder.setBuilder(); player = new Player(builder.getBody(), viewport ,touchpad); target = new B2dSteeringEntity(builder.getBody(), 10); rayHandler = new RayHandler(world); rayHandler.setAmbientLight(.2f); rayHandler.setShadows(true); rayHandler.setBlurNum(1); ptLight = new PointLight(rayHandler, 150, Color.CYAN, 6, 0, 0); ptLight.attachToBody(builder.getBody()); ptLight.setSoftnessLength(0f); for (int i = 0; i < 800; i++){ builder = new BodyDirector(new StaticBodyBuilder(world, (float) Math.random() * 100, (float) Math.random() * 100, (float) Math.random() * 50, 128f, 1.0f, true)); builder.setBuilder(); } Arrive<Vector2> arriveSB = new Arrive<Vector2>(entity, target) .setTimeToTarget(0.01f) .setArrivalTolerance(2f) .setDecelerationRadius(10); entity.setBehavior(arriveSB); }