Example usage for com.badlogic.gdx.math Vector2 add

List of usage examples for com.badlogic.gdx.math Vector2 add

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 add.

Prototype

@Override
    public Vector2 add(Vector2 v) 

Source Link

Usage

From source file:org.matheusdev.ror.controller.component.ComponentNetwork.java

License:Open Source License

@Override
public void apply(Entity entity) {
    Vector2 entityPos = entity.getPos();
    Vector2 posDiff = posDiffPool.set(remoteState.posX - entityPos.x, remoteState.posY - entityPos.y);
    float distance = posDiff.len();

    if (distance > 0.5f) {
        entity.getBody().setTransform(remoteState.posX, remoteState.posY, remoteState.angle);
        System.out.println("Set position to: " + remoteState.posX + ", " + remoteState.posY);
    } else if (distance > 0.1f) {
        entity.getBody().setTransform(entityPos.add(posDiff.scl(0.1f)), remoteState.angle);
    }/*from w ww  .  java2  s  .  c  o m*/

    entity.getBody().setLinearVelocity(remoteState.velX, remoteState.velY);
}

From source file:quantum.game.Bot.java

License:Open Source License

private int gatherConnectedPlanetsRecursive(Simulation sim, Planet planet, Vector2 center) {
    center.add(planet.getPosition());
    visited.add(planet);//from w  ww  . ja  v a 2 s.c o  m
    unvisited.remove(planet);
    int num_planets = 1;
    component_size++;
    if (component_size > 3)
        return num_planets;

    for (int neighbour : planet.getReachablePlanets()) {
        Planet neighbour_planet = sim.getPlanet(neighbour);
        if (neighbour_planet.getOwner() == planet.getOwner() && visited.contains(neighbour_planet) == false)
            num_planets += gatherConnectedPlanetsRecursive(sim, neighbour_planet, center);
    }

    return num_planets;
}

From source file:quantum.game.Planet.java

License:Open Source License

public void spawnCreature() {
    Vector2 pos = new Vector2(new Vector2(sim.rand() - sim.rand(), sim.rand() - sim.rand()).nor()
            .scl(radius + Constants.BOID_MIN_ORBIT
                    + (float) Math.random() * (Constants.BOID_MAX_ORBIT - Constants.BOID_MIN_ORBIT)));
    float angle = (float) Math.toDegrees(Math.atan2(pos.y, pos.x)) + 90;
    pos.add(this.pos);
    Creature creature = new Creature(sim, getId(), owner, pos.x, pos.y, angle, strength, health, speed);
    creatures.add(creature);//from  ww w .  j a  va 2 s. c om
    sim.addObject(creature);
    creature.setScale(1);
}

From source file:quantum.game.Planet.java

License:Open Source License

public void spawnTree() {
    int idx = last_idx + (int) (sim.rand(10, 110));
    last_idx = idx % 359;//w ww.  j  a v a 2 s  .c  o m
    idx = idx % 359;
    Vector2 pos = new Vector2(points[idx * 2] * radius, points[idx * 2 + 1] * radius);
    pos.add(this.pos);
    Tree tree = new Tree(sim, pos, id);
    trees.add(tree);
    sim.addObject(tree);
}

From source file:se.angergard.game.system.PlayerSystem.java

License:Apache License

private void sendRemoveFloorEntity(Vector2 tileChange) {
    if (holeCreated) {
        return;//ww  w . j  a  v a  2  s .  co m
    }
    holeCreated = true;

    Sprite sprite = Objects.SPRITE_MAPPER.get(player).sprite;
    Vector2 playerPosition = new Vector2(sprite.getX() + sprite.getWidth() / 2,
            sprite.getY() + sprite.getHeight() / 2);

    Entity entity = new Entity();

    RemoveFloorComponent removeFloorComponent = new RemoveFloorComponent();
    removeFloorComponent.playerPosition = playerPosition.add(tileChange);

    entity.add(removeFloorComponent);

    engine.addEntity(entity);
}