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

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

Introduction

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

Prototype

Vector2 Zero

To view the source code for com.badlogic.gdx.math Vector2 Zero.

Click Source Link

Usage

From source file:com.tnf.ptm.entities.planet.PlanetManager.java

License:Apache License

private boolean recoverObj(PtmObject obj, float toNp, float npMinH) {
    if (npMinH < toNp) {
        return false;
    }//  www .ja  v  a2  s. c  om
    if (!(obj instanceof PtmShip)) {
        return false;
    }
    PtmShip ship = (PtmShip) obj;
    Hull hull = ship.getHull();
    if (hull.config.getType() == HullConfig.Type.STATION) {
        return false;
    }
    float fh = myNearestPlanet.getFullHeight();
    Vector2 npPos = myNearestPlanet.getPos();
    Vector2 toShip = PtmMath.distVec(npPos, ship.getPosition());
    float len = toShip.len();
    if (len == 0) {
        toShip.set(0, fh);
    } else {
        toShip.scl(fh / len);
    }
    toShip.add(npPos);
    Body body = hull.getBody();
    body.setTransform(toShip, 0);
    body.setLinearVelocity(Vector2.Zero);
    PtmMath.free(toShip);
    return true;
}

From source file:com.tnf.ptm.entities.ship.EmWave.java

License:Apache License

@Override
public boolean update(PtmGame game, PtmShip owner, boolean tryToUse) {
    if (!tryToUse) {
        return false;
    }/* w w w  . ja v a  2  s .  c  o  m*/
    Vector2 ownerPos = owner.getPosition();
    for (PtmObject o : game.getObjMan().getObjs()) {
        if (!(o instanceof PtmShip) || o == owner) {
            continue;
        }
        PtmShip oShip = (PtmShip) o;
        if (!game.getFactionMan().areEnemies(oShip, owner)) {
            continue;
        }
        Vector2 oPos = o.getPosition();
        float dst = oPos.dst(ownerPos);
        float perc = KnockBack.getPerc(dst, MAX_RADIUS);
        if (perc <= 0) {
            continue;
        }
        float duration = perc * myConfig.duration;
        oShip.disableControls(duration, game);
    }
    ParticleSrc src = new ParticleSrc(myConfig.cc.effect, MAX_RADIUS, DraLevel.PART_BG_0, new Vector2(), true,
            game, ownerPos, Vector2.Zero, 0);
    game.getPartMan().finish(game, src, ownerPos);
    return true;
}

From source file:com.tnf.ptm.entities.ship.KnockBack.java

License:Apache License

@Override
public boolean update(PtmGame game, PtmShip owner, boolean tryToUse) {
    if (!tryToUse) {
        return false;
    }/* ww w.  jav  a 2 s .c  om*/
    Vector2 ownerPos = owner.getPosition();
    for (PtmObject o : game.getObjMan().getObjs()) {
        if (o == owner || !o.receivesGravity()) {
            continue;
        }
        Vector2 oPos = o.getPosition();
        float dst = oPos.dst(ownerPos);
        if (dst == 0) {
            continue; // O__o
        }
        float perc = getPerc(dst, MAX_RADIUS);
        if (perc <= 0) {
            continue;
        }
        Vector2 toO = PtmMath.distVec(ownerPos, oPos);
        float accLen = myConfig.force * perc;
        toO.scl(accLen / dst);
        o.receiveForce(toO, game, false);
        PtmMath.free(toO);
    }
    ParticleSrc src = new ParticleSrc(myConfig.cc.effect, MAX_RADIUS, DraLevel.PART_BG_0, new Vector2(), true,
            game, ownerPos, Vector2.Zero, 0);
    game.getPartMan().finish(game, src, ownerPos);
    return true;
}

From source file:com.tnf.ptm.entities.ship.ShipBuilder.java

License:Apache License

private PrismaticJoint createDoorJoint(Body shipBody, World w, Vector2 shipPos, Vector2 doorRelPos,
        float shipAngle) {
    Body doorBody = createDoorBody(w, shipPos, doorRelPos, shipAngle);
    PrismaticJointDef jd = new PrismaticJointDef();
    jd.initialize(shipBody, doorBody, shipPos, Vector2.Zero);
    jd.localAxisA.set(1, 0);//from w  ww .  java 2 s  . co m
    jd.collideConnected = false;
    jd.enableLimit = true;
    jd.enableMotor = true;
    jd.lowerTranslation = 0;
    jd.upperTranslation = Door.DOOR_LEN;
    jd.maxMotorForce = 2;
    return (PrismaticJoint) w.createJoint(jd);
}

From source file:com.tnf.ptm.entities.ship.Teleport.java

License:Apache License

public void maybeTeleport(PtmGame game, PtmShip owner) {
    if (!myShouldTeleport) {
        return;// w  w w  .  jav a2s .  c o m
    }

    TextureAtlas.AtlasRegion tex = game.getTexMan().getTexture(TEX_PATH);
    float blipSz = owner.getHull().config.getApproxRadius() * 3;
    game.getPartMan().blip(game, owner.getPosition(), PtmMath.rnd(180), blipSz, 1, Vector2.Zero, tex);
    game.getPartMan().blip(game, myNewPos, PtmMath.rnd(180), blipSz, 1, Vector2.Zero, tex);

    float newAngle = owner.getAngle() + myAngle;
    Vector2 newSpd = PtmMath.getVec(owner.getSpd());
    PtmMath.rotate(newSpd, myAngle);

    Body body = owner.getHull().getBody();
    body.setTransform(myNewPos, newAngle * PtmMath.degRad);
    body.setLinearVelocity(newSpd);

    PtmMath.free(newSpd);
}

From source file:com.tnf.ptm.entities.ship.UnShield.java

License:Apache License

@Override
public boolean update(PtmGame game, PtmShip owner, boolean tryToUse) {
    if (!tryToUse) {
        return false;
    }//from w  ww. j  ava  2  s  .  co m
    Vector2 ownerPos = owner.getPosition();
    for (PtmObject o : game.getObjMan().getObjs()) {
        if (!(o instanceof PtmShip) || o == owner) {
            continue;
        }
        PtmShip oShip = (PtmShip) o;
        Shield shield = oShip.getShield();
        if (shield == null) {
            continue;
        }
        float shieldLife = shield.getLife();
        if (shieldLife <= 0) {
            continue;
        }
        if (!game.getFactionMan().areEnemies(oShip, owner)) {
            continue;
        }
        Vector2 oPos = o.getPosition();
        float dst = oPos.dst(ownerPos);
        float perc = KnockBack.getPerc(dst, MAX_RADIUS);
        if (perc <= 0) {
            continue;
        }
        float amount = perc * myConfig.amount;
        if (shieldLife < amount) {
            amount = shieldLife;
        }
        oShip.receiveDmg(amount, game, ownerPos, DmgType.ENERGY);
    }
    ParticleSrc src = new ParticleSrc(myConfig.cc.effect, MAX_RADIUS, DraLevel.PART_BG_0, new Vector2(), true,
            game, ownerPos, Vector2.Zero, 0);
    game.getPartMan().finish(game, src, ownerPos);
    return true;
}

From source file:com.tnf.ptm.entities.StarPort.java

License:Apache License

private static void blip(PtmGame game, PtmShip ship) {
    TextureAtlas.AtlasRegion tex = game.getTexMan().getTexture(Teleport.TEX_PATH);
    float blipSz = ship.getHull().config.getApproxRadius() * 10;
    game.getPartMan().blip(game, ship.getPosition(), PtmMath.rnd(180), blipSz, 1, Vector2.Zero, tex);
}

From source file:com.tnf.ptm.gfx.particle.ParticleSrc.java

License:Apache License

private void updateSpd(PtmGame game, Vector2 baseSpd, Vector2 basePos) {
    if (isContinuous()) {
        if (!isWorking()) {
            return;
        }/*from  w ww  .j  a v  a  2  s .co m*/
    } else {
        if (myFloatedUp) {
            return;
        }
        myFloatedUp = true;
    }
    if (!myInheritsSpd) {
        baseSpd = Vector2.Zero;
    }
    if (!myConfig.floatsUp) {
        setSpd(baseSpd);
        return;
    }
    Planet np = game.getPlanetMan().getNearestPlanet();
    Vector2 spd = np.getAdjustedEffectSpd(basePos, baseSpd);
    setSpd(spd);
    PtmMath.free(spd);
}

From source file:com.tnf.ptm.gfx.particle.SpecialEffects.java

License:Apache License

public void explodeShip(PtmGame game, Vector2 pos, float sz) {
    PartMan pm = game.getPartMan();/*from w  ww  . j av a 2  s.c om*/
    ParticleSrc smoke = new ParticleSrc(myShipExplSmoke, 2 * sz, DraLevel.PART_FG_0, new Vector2(), false, game,
            pos, Vector2.Zero, 0);
    pm.finish(game, smoke, pos);
    ParticleSrc fire = new ParticleSrc(myShipExplFire, .7f * sz, DraLevel.PART_FG_1, new Vector2(), false, game,
            pos, Vector2.Zero, 0);
    pm.finish(game, fire, pos);
    pm.blinks(pos, game, sz);
}

From source file:com.tnf.ptm.handler.input.Guardian.java

License:Apache License

@Override
public Vector2 getDestSpd() {
    return myTarget == null ? Vector2.Zero : myTarget.getSpd();
}