List of usage examples for com.badlogic.gdx.math Vector2 cpy
@Override
public Vector2 cpy()
From source file:AITest.Box2DSteeringEntity.java
@Override public Vector2 angleToVector(Vector2 outVector, float angle) { outVector = VectorUtils.AngleToVector(angle); return outVector.cpy(); }
From source file:com.dagondev.drop.GameScreen.java
License:Apache License
/** * * @param pos1 Player 1 body position/*from ww w. j a v a 2s. c o m*/ * @param pos2 Player 2 body position * @return Delta between two player positions */ private Vector2 getMiddleOfPlayers(Vector2 pos1, Vector2 pos2) { if (pos1 == null || pos2 == null) return null; return pos2.cpy().sub(pos1); }
From source file:com.dongbat.game.ability.types.HotBlow.java
/** * Cast ability to the target when entity caster cast by using input on screen * * @param world artemis world/*from w ww . jav a 2 s . c o m*/ * @param caster entity which use ability * @param target target of ability */ @Override public void cast(World world, Entity caster, Vector2 target) { Vector2 playerPosition = PhysicsUtil.getPosition(world, caster); float sourceRadius = PhysicsUtil.getRadius(world, caster); Array<Entity> foundList = WorldQueryUtil.findAnyInRadius(world, playerPosition, radius + sourceRadius); Array<Entity> filterList = WorldQueryUtil.filterEntityInRay(world, foundList, playerPosition, target, degree); for (Entity e : filterList) { if (e != caster) { BuffUtil.addBuff(world, caster, e, "VacuumForced", 1000, 1, "forceStrength", -forceStrength, "target", playerPosition.cpy(), "ignoreMass", ignoreMass); if (WorldQueryUtil.isFood(world, e.getId())) { // EntityUtil.getComponent(world, e, Food.class).setToxic(true); } } } // BuffUtil.addBuff(world, caster, caster, "Vacuum", duration, 1); }
From source file:com.dongbat.game.ability.types.SplitAndJoin.java
@Override public void cast(World world, Entity caster, Vector2 target) { AbilityComponent playerAbilityList = EntityUtil.getComponent(world, caster, AbilityComponent.class); AbilityInfo info = playerAbilityList.getAbility("SplitAndJoin"); if (info == null) { return;/*from ww w . j a v a2 s. c om*/ } Vector2 position = PhysicsUtil.getPosition(world, caster); UnitMovement ms = EntityUtil.getComponent(world, caster, UnitMovement.class); Vector2 direction = ms.getDirectionVelocity(); if (direction == null) { return; } float radius = PhysicsUtil.getRadius(world, caster); if (radius <= Constants.PHYSICS.MIN_RADIUS * 2) { return; } float newRadius = radius / 1.41f; // BuffUtil.addBuff(world, caster, caster, "Forced", 1500, 1, "forceStrength", 100, "direction", direction.cpy().scl(-1)); PhysicsUtil.setRadius(world, caster, newRadius); Entity bullet = UnitFactory.createProjectileUnit(world, caster, direction.cpy().nor().scl(radius + newRadius).add(position.cpy()), newRadius, true, true, true); ObjectMap<String, Object> args = new ObjectMap<String, Object>(); // Display display = EntityUtil.getComponent(world, caster, Display.class); // TextureAtlas split = AssetUtil.getUnitAtlas().get("split"); // Animation animation = new Animation(0.075f, split.getRegions()); // animation.setPlayMode(Animation.PlayMode.LOOP); // display.setGetOverridenStart(TimeUtil.getCurrentFrame(world)); // display.setOverridenDuration(1500); // display.setOverridenAnimation(new AnimatedSprite(animation)); // args.put("forceStrength", 100); // args.put("direction", direction.cpy().scl(1)); // BuffUtil.addBuff(world, caster, bullet, "DelayBuff", 0, 1, "buffName", "Forced", "duration", 3000, "args", args); BuffUtil.addBuff(world, caster, bullet, "Forced", 500, 1, "forceStrength", 20, "direction", direction.cpy().scl(1), "ignoreMass", true); args.put("feedPerSecond", 2f); BuffUtil.addBuff(world, caster, bullet, "DelayBuff", 1000, 1, "buffName", "Feed", "duration", -1, "args", args); BuffUtil.addBuff(world, bullet, bullet, "AttractFood", -1, 1); // BuffUtil.addBuff(world, bullet, bullet, "Feed", -1, 1, "feedPerSecond", 0.55f); }
From source file:com.dongbat.game.ai.tasks.AvoidToBeEaten.java
@Override public void run() { Entity e = getObject();/*from w w w . j a v a 2 s. c o m*/ float radius = PhysicsUtil.getRadius(e.getWorld(), e); Vector2 currentPos = PhysicsUtil.getPosition(e.getWorld(), e); Vector2 directionToPlayer = null; float distance2 = 999999999; Array<Entity> anyInRadius = WorldQueryUtil.findAnyInRadius(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), 10); for (Entity entity : anyInRadius) { if (radius < PhysicsUtil.getRadius(entity.getWorld(), entity)) { Vector2 nearPlayerPos = PhysicsUtil.getPosition(e.getWorld(), entity); float newDistance2 = nearPlayerPos.cpy().sub(currentPos.cpy()).len2(); if (newDistance2 < distance2) { directionToPlayer = nearPlayerPos.cpy().sub(currentPos); distance2 = newDistance2; } } } if (directionToPlayer != null && distance2 > 0) { MovementUtil.addMoveInput(e.getWorld(), e, directionToPlayer.cpy().scl(-1)); } success(); }
From source file:com.dongbat.game.ai.tasks.FindNearestFoodTask.java
@Override public void run() { Entity e = getObject();//from w w w.j ava 2s. c om // UnitMovement unitMovement = EntityUtil.getComponent(e.getWorld(), e, UnitMovement.class); Array<Entity> foodInRadius = findColdFoodInRadius(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), 50); // Array<Entity> foodInMap = findColdFoodInRadius(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), 5000); Entity nearestFood = findNearestEntityInList(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), foodInRadius); Vector2 currentPos = PhysicsUtil.getPosition(e.getWorld(), e); if (nearestFood == null) { // Entity mapsFood = findNearestEntityInList(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), foodInMap); // if (mapsFood == null) { // if (unitMovement.getDirectionVelocity() == null) { // MovementUtil.addMoveInput(e.getWorld(), e, currentPos); // } // } else { // Vector2 foodPosition = PhysicsUtil.getPosition(mapsFood.getWorld(), mapsFood); // Vector2 destinationToFood = foodPosition.cpy().sub(currentPos); // MovementUtil.addMoveInput(e.getWorld(), e, destinationToFood); // } } else { Vector2 foodPosition = PhysicsUtil.getPosition(e.getWorld(), nearestFood); Vector2 destinationToFood = foodPosition.cpy().sub(currentPos); MovementUtil.addMoveInput(e.getWorld(), e, destinationToFood); } success(); }
From source file:com.dongbat.game.ai.tasks.FindNearestPlayerTask.java
@Override public void run() { Entity e = getObject();//from w w w .j a va2s . c o m Array<Entity> playerInRadius = findPlayerWithAiInRadius(e.getWorld(), e, PhysicsUtil.getPosition(e.getWorld(), e), 100); Entity nearestPlayer = findNearestEntityInList(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), playerInRadius); Vector2 currentPos = PhysicsUtil.getPosition(e.getWorld(), e); if (nearestPlayer == null) { fail(); } else { if (BuffUtil.hasBuff(nearestPlayer.getWorld(), nearestPlayer, "Respawn")) { fail(); } Vector2 nearPlayerPos = PhysicsUtil.getPosition(e.getWorld(), nearestPlayer); Vector2 directionToPlayer = nearPlayerPos.cpy().sub(currentPos); MovementUtil.addMoveInput(e.getWorld(), e, directionToPlayer); } success(); }
From source file:com.dongbat.game.ai.tasks.MoveToQueenTask.java
@Override public void run() { Entity e = getObject();/* ww w .j ava2s . com*/ Array<Entity> foodInRadius = WorldQueryUtil.findQueenInRadius(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), 350); Entity nearestQueen = findNearestEntityInList(e.getWorld(), PhysicsUtil.getPosition(e.getWorld(), e), foodInRadius); Vector2 currentPos = PhysicsUtil.getPosition(e.getWorld(), e); if (nearestQueen == null) { return; } Vector2 foodPosition = PhysicsUtil.getPosition(e.getWorld(), nearestQueen); Vector2 destinationToFood = foodPosition.cpy().sub(currentPos); MovementUtil.addMoveInput(e.getWorld(), e, destinationToFood); success(); }
From source file:com.dongbat.game.buff.effects.HotBlow.java
@Override public void update(World world, Entity source, Entity target) { Vector2 playerPosition = PhysicsUtil.getPosition(world, source); UnitMovement unitMs = EntityUtil.getComponent(world, target, UnitMovement.class); if (unitMs.getDirectionVelocity() == null) { return;/*from www . j a v a 2 s . co m*/ } Array<Entity> foundList = WorldQueryUtil.findAnyInRadius(world, playerPosition, radius); Array<Entity> filterList = WorldQueryUtil.filterEntityInRay(world, foundList, playerPosition, unitMs.getDirectionVelocity(), degree); for (Entity e : filterList) { if (e != source) { Vector2 victimPosition = PhysicsUtil.getPosition(world, e); Vector2 direction = victimPosition.cpy().sub(playerPosition).cpy().scl(-1).nor(); BuffUtil.addBuff(world, source, e, "HotBlowForced", duration, 1, "forceStrength", forceStrength, "direction", direction.cpy().scl(-1)); BuffUtil.addBuff(world, source, e, "ToxicFood", 400, 1); } } }
From source file:com.dongbat.game.buff.effects.ProduceFoodSchedule.java
@Override public void update(World world, Entity source, Entity target) { long currentFrame = TimeUtil.getCurrentFrame(world); float elapsed = currentFrame - lastRest; if (!resting && elapsed > overheatFrame) { lastRest = currentFrame;/*from w w w . jav a 2s . c o m*/ resting = true; } if (resting && elapsed > overheatFrame + cooldownFrame) { resting = false; } if (resting) { return; } if (ECSUtil.getFrame(world) % scheduleFrame == 0) { Vector2 position = PhysicsUtil.getPosition(world, target); UnitMovement unitMovement = EntityUtil.getComponent(world, source, UnitMovement.class); Vector2 destination = unitMovement.getDirectionVelocity(); float degree = 60; for (int i = 0; i < 1; i++) { float d = ECSUtil.getRandom(world).getFloat(-degree / 2, degree / 2); Vector2 direction = destination.cpy().scl(-1).nor().rotate(d); if (direction.cpy().nor().len2() == 0) { //TODO: fixxxxxxxxxxxxx this direction = new Vector2(ECSUtil.getRandom(world).getFloat(-1, 1), ECSUtil.getRandom(world).getFloat(-1, 1)); } Entity food = EntityFactory.createFood(world, position, UuidUtil.getUuid(source)); // TODO: food expiring system BuffUtil.addBuff(world, source, food, "ToBeRemoved", 3000, 1); BuffUtil.addBuff(world, source, food, "ToxicFood", 400, 1); BuffUtil.addBuff(world, source, food, "Forced", (int) (600 * ECSUtil.getRandom(world).getFloat(0.5f, 1.25f)), 1, "forceStrength", 0.75f, "direction", direction); } } }