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

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

Introduction

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

Prototype

public Vector2 mul(Matrix3 mat) 

Source Link

Document

Left-multiplies this vector by the given matrix

Usage

From source file:com.hajnar.GravityShip.GameObjects.GameCamera.java

License:Apache License

public Vector2 follow(Player player) {
    Vector2 playerVelocity = player.getBody().getLinearVelocity();
    offset.add(-offset.x / 20f, -offset.y / 20f);
    offset.add(playerVelocity.mul(1.2f));
    if (offset.x > 200)
        offset.x = 200;//from   w w  w  .j a va2s .  co m
    else if (offset.x < -200)
        offset.x = -200;
    if (offset.y > 150)
        offset.y = 150;
    else if (offset.y < -150)
        offset.y = -150;
    cameraTranslation.set(player.getBody().getPosition().mul(Helper.BOX_TO_WORLD).sub(position.x - offset.x,
            position.y - offset.y));
    translate(cameraTranslation);
    return cameraTranslation;
}

From source file:com.hajnar.GravityShip.GameObjects.GameCamera.java

License:Apache License

public Vector2 followWithZooming(Player player, float delta) {
    Vector2 playerVelocity = player.getBody().getLinearVelocity();
    float playerVelocityLen = playerVelocity.len();
    offset.add(-offset.x / 20f, -offset.y / 20f);
    offset.add(playerVelocity.mul(1.2f));
    if (offset.x > 200)
        offset.x = 200;//w  ww. j  a v a2  s  .  c  o m
    else if (offset.x < -200)
        offset.x = -200;
    if (offset.y > 150)
        offset.y = 150;
    else if (offset.y < -150)
        offset.y = -150;
    cameraTranslation.set(player.getBody().getPosition().mul(Helper.BOX_TO_WORLD).sub(position.x - offset.x,
            position.y - offset.y));
    translate(cameraTranslation);
    if (playerVelocityLen < 20)
        if (playerVelocityBefore < playerVelocityLen && playerVelocityLen > 2)
            changeZoom(0.27f * delta);
        else
            changeZoom(-0.27f * delta);
    playerVelocityBefore = playerVelocityLen;
    return cameraTranslation;

}

From source file:com.hajnar.GravityShip.GameWorld.java

License:Apache License

public void updateBlackHoles(float delta) {
    int len = blackHoles.size();
    for (int i = 0; i < len; i++) {
        blackHoles.get(i).update(delta);
        Vector2 playerPosition = player.getBody().getPosition();
        Vector2 holePosition = blackHoles.get(i).getBody().getPosition();
        Vector2 gravityVector = (holePosition.sub(playerPosition));
        float gravityForce = blackHoles.get(i).getStrength() / gravityVector.len2();
        gravityVector.nor();/*  w w  w  .j  av a 2 s  .c  o  m*/
        gravityVector.mul(gravityForce);
        player.getBody().applyForceToCenter(gravityVector);
    }
}

From source file:com.sertaogames.cactus2d.components.BoxCollider.java

License:Open Source License

public BoxCollider(Vector2 size, Vector2 offset) {
    this.offset = offset;
    size.mul(Cactus2DApplication.INV_PHYSICS_SCALE * 0.5f);
    PolygonShape poly = new PolygonShape();
    poly.setAsBox(size.x, size.y);//from   w ww.j  ava2  s .  c om
    shape = poly;
}

From source file:com.sertaogames.cactus2d.components.TileMapPhysics.java

License:Open Source License

private void createBodyFromObject(Vector2 pos, Vector2 size) {
    Body rigidbody;//from  www . ja  v a  2 s .  co  m
    PolygonShape groundPoly = new PolygonShape();

    size.mul(Cactus2DApplication.INV_PHYSICS_SCALE * 0.5f);
    groundPoly.setAsBox(size.x, size.y);

    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.fixedRotation = true;
    groundBodyDef.type = BodyType.StaticBody;
    rigidbody = gameObject.world.createBody(groundBodyDef);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = groundPoly;
    fixtureDef.filter.groupIndex = 0;
    fixtureDef.filter.categoryBits = 0x4;
    rigidbody.createFixture(fixtureDef);
    groundPoly.dispose();

    pos.add(transform.getPosition());
    pos.mul(Cactus2DApplication.INV_PHYSICS_SCALE);
    rigidbody.setTransform(pos, transform.getAngle());
    rigidbody.setUserData(gameObject);
    bodies.add(rigidbody);
}

From source file:com.sertaogames.cactus2d.components.TileMapPhysics.java

License:Open Source License

private void createBodyFromBlocks(int begin, int last, int i) {
    Vector2 tileSize = new Vector2(tm.tilemap.tileWidth, tm.tilemap.tileHeight);

    Body rigidbody;//from  w  ww  .  j ava 2 s . c  om
    PolygonShape groundPoly = new PolygonShape();
    int width = last - begin + 1;
    float height = tileSize.y;
    width *= tileSize.x;
    // System.out.println("i: "+i+" width: "+width);
    Vector2 temp = new Vector2(width, tileSize.y);
    temp.mul(Cactus2DApplication.INV_PHYSICS_SCALE * 0.5f);
    groundPoly.setAsBox(temp.x, temp.y);

    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.fixedRotation = true;
    groundBodyDef.type = BodyType.StaticBody;
    rigidbody = gameObject.world.createBody(groundBodyDef);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = groundPoly;
    fixtureDef.filter.groupIndex = 0;
    fixtureDef.filter.categoryBits = 0x4;
    rigidbody.createFixture(fixtureDef);
    groundPoly.dispose();

    temp.set(
            new Vector2(begin * tileSize.x + width / 2, (tm.tilemap.height - i) * tileSize.y - tileSize.y / 2));
    temp.add(transform.getPosition());
    temp.mul(Cactus2DApplication.INV_PHYSICS_SCALE);
    rigidbody.setTransform(temp, transform.getAngle());
    rigidbody.setUserData(gameObject);
    bodies.add(rigidbody);
}

From source file:fr.plnech.igem.game.AbstractGameActivity.java

License:Open Source License

public void setPhysicsCoeff(float coeff) {
    final Vector2 gravity = physicsWorld.getGravity();
    final Vector2 physicsVector = currentGame.getPhysicsVector();
    final float minCoeff = 0.5f;
    if (gravity.x < physicsVector.x * minCoeff || gravity.y < physicsVector.y * minCoeff) {
        return;/*from w  ww  . j a v a2s  .  c o m*/
    }
    physicsWorld.setGravity(gravity.mul(coeff));
}