Java Code Examples for com.badlogic.gdx.math.Vector2.add()

The following are Jave code examples for showing how to use add() of the com.badlogic.gdx.math.Vector2 class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: cocos2d-java   File: Polygon.java   Source Code and License Vote up 5 votes
/**平移 变更形状	更新AABB
 * @param x
 * @param y */
public final void trans(final float x,final float y){
	for(Vector2 v: points){
		v.add(x, y);
	}
	computeShapeAABB();
	computeShapeCenter();
}
 
Example 2
Project: cocos2d-java   File: Polygon.java   Source Code and License Vote up 5 votes
/**平移 变更形状	更新AABB
 * @param tran */
public final void trans(final Vector2 tran){
	for(Vector2 v: points){
		v.add(tran);
	}
	computeShapeAABB();
	computeShapeCenter();
}
 
Example 3
Project: cocos2d-java   File: AABBShape.java   Source Code and License Vote up 5 votes
public void trans(float x, float y) {
	for(Vector2 v:points){
		v.add(x,y);
	}
	this.computeShapeAABB();
	computeShapeCenter();
}
 
Example 4
Project: GDX-Engine   File: VRope.java   Source Code and License Vote up 5 votes
public void resetWithPoints(Vector2 pointA, Vector2 pointB) {
	float distance = pointA.dst(pointB);
	Vector2 diffVector = pointA.sub(pointB);
	float multiplier = distance / (numPoints - 1);
	for(int i=0;i<numPoints;i++) {
		Vector2 tmpVector = pointA.add(diffVector.nor().mul(multiplier*i*(1-antiSagHack)));
		VPoint tmpPoint = vPoints.get(i);
		tmpPoint.setPos(tmpVector.x, tmpVector.y);
		
	}
}
 
Example 5
Project: miniventure   File: Player.java   Source Code and License Vote up 5 votes
public void checkInput(float delta, @NotNull Vector2 mouseInput) {
	// checks for keyboard input to move the player.
	// getDeltaTime() returns the time passed between the last and the current frame in seconds.
	int speed = Tile.SIZE * 5; // this is technically in units/second.
	Vector2 movement = new Vector2();
	if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) movement.x--;
	if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) movement.x++;
	if(Gdx.input.isKeyPressed(Input.Keys.UP)) movement.y++;
	if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) movement.y--;
	
	movement.nor();
	
	movement.add(mouseInput);
	movement.nor();
	
	movement.scl(speed * delta);
	
	move(movement.x, movement.y);
	
	if(pressingKey(Input.Keys.Q)) cycleHeldItem(false);
	if(pressingKey(Input.Keys.E)) cycleHeldItem(true);
	
	if(pressingKey(Input.Keys.C))
		attack();
	else if(pressingKey(Input.Keys.V))
		interact();
	
	heldItem = heldItem == null ? null : heldItem.consume();
}
 
Example 6
Project: Klooni1010   File: Piece.java   Source Code and License Vote up 5 votes
Vector2 calculateGravityCenter() {
    int filledCount = 0;
    Vector2 result = new Vector2();
    for (int i = 0; i < cellRows; ++i) {
        for (int j = 0; j < cellCols; ++j) {
            if (shape[i][j]) {
                filledCount++;
                result.add(
                        pos.x + j * cellSize - cellSize * 0.5f,
                        pos.y + i * cellSize - cellSize * 0.5f);
            }
        }
    }
    return result.scl(1f / filledCount);
}
 
Example 7
Project: Mindustry   File: EnemyType.java   Source Code and License Vote up 4 votes
public void move(Enemy enemy){
    float speed = this.speed + 0.04f * enemy.tier;
    float range = this.range + enemy.tier * 5;

    if(Net.client() && Net.active()){
        enemy.interpolate(); //TODO? better structure for interpolation
        return;
    }

    Tile core = Vars.control.getCore();

    if(enemy.idletime > maxIdleLife){
        enemy.onDeath();
        return;
    }

    boolean nearCore = enemy.distanceTo(core.worldx(), core.worldy()) <= range - 18f && stopNearCore;
    Vector2 vec;

    if(nearCore){
        vec = Tmp.v1.setZero();
        if(targetCore) enemy.target = core.entity;
    }else{
        vec = Vars.world.pathfinder().find(enemy);
        vec.sub(enemy.x, enemy.y).limit(speed);
    }

    Vector2 shift = Tmp.v3.setZero();
    float shiftRange = enemy.hitbox.width + 2f;
    float avoidRange = shiftRange + 4f;
    float attractRange = avoidRange + 7f;
    float avoidSpeed = this.speed/2.7f;

    Entities.getNearby(Vars.control.enemyGroup, enemy.x, enemy.y, range, en -> {
        Enemy other = (Enemy)en;
        if(other == enemy) return;
        float dst = other.distanceTo(enemy);

        if(dst < shiftRange){
            float scl = Mathf.clamp(1.4f - dst / shiftRange) * mass * 1f/mass;
            shift.add((enemy.x - other.x) * scl, (enemy.y - other.y) * scl);
        }else if(dst < avoidRange){
            Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
            shift.add(Tmp.v2.scl(1.1f));
        }else if(dst < attractRange && !nearCore){
            Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
            shift.add(Tmp.v2.scl(-1));
        }
    });

    shift.limit(1f);
    vec.add(shift.scl(0.5f));

    enemy.move(vec.x * Timers.delta(), vec.y * Timers.delta());

    updateTargeting(enemy, nearCore);
}
 
Example 8
Project: feup-lpoo-armadillo   File: PolygonIntersector.java   Source Code and License Vote up 4 votes
/**
 * Computes the Polygon Properties of a given Polygon.
 *
 * @param polygon The polygon to be analyzed.
 * @return The Polygon Properties computed.
 */
public static PolygonProperties computePolygonProperties(Vector2[] polygon) {
    PolygonProperties polygonProperties = null;

    int count = polygon.length;

    if (count >= 3) {
        Vector2 centroid = new Vector2(0, 0);
        float area = 0;

        Vector2 refPoint = new Vector2(0, 0);
        float threeInverse = 1 / 3f;

        for (int i = 0; i < count; i++) {
            /*
 * Create a new vector to represent the reference point for
 * forming triangles. Then use refPoint, polygonVertex and
 * thirdTriangleVertex as vertices of a triangle.
 */
            refPoint.set(0, 0);
            Vector2 polygonVertex = polygon[i];
            Vector2 thirdTriangleVertex = i + 1 < count ? polygon[i + 1]
                    : polygon[0];

            Vector2 firstDirectionVector = polygonVertex.sub(refPoint);
            Vector2 secondDirectionVector = thirdTriangleVertex
                    .sub(refPoint);

            float triangleArea = firstDirectionVector
                    .crs(secondDirectionVector) / 2;
            area += triangleArea;

/* Area weighted centroid */
            centroid.add(refPoint.add(polygonVertex)
                    .add(thirdTriangleVertex)
                    .scl(triangleArea * threeInverse));
        }

        if (area > EPSILON) {
            centroid.scl(1 / area);
        } else {
            area = 0;
        }

        polygonProperties = new PolygonProperties(centroid, area);
    }

    return polygonProperties;
}
 
Example 9
Project: TH902   File: GameHelper.java   Source Code and License Vote up 4 votes
public static void chase(Vector2 toModify, final Vector2 target, final float speed) {
	vct2_tmp1.set(target).sub(toModify);
	toModify.add(vct2_tmp1.nor().scl(speed));
}