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:com.tnf.ptm.common.GalaxyFiller.java

License:Apache License

public Vector2 getPlayerSpawnPos(PtmGame game) {
    Vector2 pos = new Vector2(Const.SUN_RADIUS * 2, 0);

    if ("planet".equals(DebugOptions.SPAWN_PLACE)) {
        Planet p = game.getPlanetMan().getPlanets().get(0);
        pos.set(p.getPos());// ww w .j a v a  2s.  co  m
        pos.x += p.getFullHeight();
    } else if (DebugOptions.SPAWN_PLACE.isEmpty() && myMainStationPos != null) {
        PtmMath.fromAl(pos, 90, myMainStationHc.getSize() / 2);
        pos.add(myMainStationPos);
    } else if ("maze".equals(DebugOptions.SPAWN_PLACE)) {
        Maze m = game.getPlanetMan().getMazes().get(0);
        pos.set(m.getPos());
        pos.x += m.getRadius();
    } else if ("trader".equals(DebugOptions.SPAWN_PLACE)) {
        HullConfig cfg = game.getHullConfigs().getConfig(new ResourceUrn("core:bus"));
        for (FarObjData fod : game.getObjMan().getFarObjs()) {
            FarObj fo = fod.fo;
            if (!(fo instanceof FarShip)) {
                continue;
            }
            if (((FarShip) fo).getHullConfig() != cfg) {
                continue;
            }
            pos.set(fo.getPos());
            pos.add(cfg.getApproxRadius() * 2, 0);
            break;
        }

    }
    return pos;
}

From source file:com.tnf.ptm.common.MapDrawer.java

License:Apache License

private void drawPlanets(GameDrawer drawer, PtmGame game, float viewDist, Planet np, Vector2 camPos,
        float heroDmgCap, float camAngle) {
    ArrayList<PtmSystem> systems = game.getPlanetMan().getSystems();
    PtmCam cam = game.getCam();/*from   w  ww  .ja va  2 s .com*/
    float circleWidth = cam.getRealLineWidth() * 6;
    float vh = cam.getViewHeight(myZoom);
    for (int i3 = 0, systemsSize1 = systems.size(); i3 < systemsSize1; i3++) {
        PtmSystem sys = systems.get(i3);
        drawer.drawCircle(myLineTex, sys.getPos(), sys.getRadius(), PtmColor.UI_MED, circleWidth, vh);
    }
    for (int i2 = 0, systemsSize = systems.size(); i2 < systemsSize; i2++) {
        PtmSystem sys = systems.get(i2);
        float dangerRad = HardnessCalc.isDangerous(heroDmgCap, sys.getDps()) ? sys.getRadius() : 0;
        Vector2 sysPos = sys.getPos();
        float rad = Const.SUN_RADIUS;
        if (camPos.dst(sysPos) - rad < viewDist) {
            drawer.draw(myStarTex, 2 * rad, 2 * rad, rad, rad, sysPos.x, sysPos.y, 0, PtmColor.WHITE);
        }

        Vector2 beltIconPos = PtmMath.getVec();
        ArrayList<SystemBelt> belts = sys.getBelts();
        for (int i1 = 0, beltsSize = belts.size(); i1 < beltsSize; i1++) {
            SystemBelt belt = belts.get(i1);
            float beltRad = belt.getRadius();
            float halfWidth = belt.getHalfWidth();
            int beltIconCount = (int) (.12f * beltRad);
            for (int i = 0; i < beltIconCount; i++) {
                float angle = 360f * i / beltIconCount;
                PtmMath.fromAl(beltIconPos, angle, beltRad);
                beltIconPos.add(sysPos);
                drawer.draw(myBeltTex, 2 * halfWidth, 2 * halfWidth, halfWidth, halfWidth, beltIconPos.x,
                        beltIconPos.y, angle * 3, PtmColor.WHITE);
            }
            float outerRad = beltRad + halfWidth;
            if (dangerRad < outerRad && HardnessCalc.isDangerous(heroDmgCap, belt.getDps())) {
                dangerRad = outerRad;
            }
        }
        PtmMath.free(beltIconPos);
        if (dangerRad < sys.getInnerRad() && HardnessCalc.isDangerous(heroDmgCap, sys.getInnerDps())) {
            dangerRad = sys.getInnerRad();
        }
        if (dangerRad > 0) {
            drawAreaDanger(drawer, dangerRad, sysPos, .5f, camAngle);
        }
    }

    ArrayList<Planet> planets = game.getPlanetMan().getPlanets();
    for (int i = 0, planetsSize = planets.size(); i < planetsSize; i++) {
        Planet planet = planets.get(i);
        Vector2 planetPos = planet.getPos();
        float fh = planet.getFullHeight();
        float dstToPlanetAtm = camPos.dst(planetPos) - fh;
        if (viewDist < dstToPlanetAtm) {
            continue;
        }
        drawer.draw(myAtmTex, 2 * fh, 2 * fh, fh, fh, planetPos.x, planetPos.y, 0, PtmColor.UI_DARK);
        float gh;
        if (dstToPlanetAtm < 0) {
            gh = planet.getMinGroundHeight() + .5f;
            drawer.draw(myPlanetCoreTex, 2 * gh, 2 * gh, gh, gh, planetPos.x, planetPos.y, planet.getAngle(),
                    PtmColor.WHITE);
            drawNpGround(drawer, game, viewDist, np, camPos);
        } else {
            gh = planet.getGroundHeight();
            drawer.draw(myPlanetTex, 2 * gh, 2 * gh, gh, gh, planetPos.x, planetPos.y, camAngle,
                    PtmColor.WHITE);
        }
        float dangerRad = HardnessCalc.isDangerous(heroDmgCap, planet.getGroundDps())
                ? gh + Const.ATM_HEIGHT / 2
                : 0;
        //      if (dangerRad < gh && HardnessCalc.isDangerous(heroDmgCap, planet.getGroundDps())) dangerRad = gh;
        if (dangerRad > 0) {
            drawAreaDanger(drawer, dangerRad, planetPos, 1, camAngle);
        }
    }
}

From source file:com.tnf.ptm.common.PtmMath.java

License:Apache License

/**
 * converts relPos (a position in a relative coordinate system defined by baseAngle and basePos) to the absolute position (which is written to pos)
 *//*from   w  ww.  j a  va 2  s.  c  o m*/
public static void toWorld(Vector2 pos, Vector2 relPos, float baseAngle, Vector2 basePos, boolean precise) {
    pos.set(relPos);
    rotate(pos, baseAngle, precise);
    pos.add(basePos);
}

From source file:com.tnf.ptm.entities.asteroid.Asteroid.java

License:Apache License

private void maybeSplit(PtmGame game) {
    if (MIN_SPLIT_SZ > mySize) {
        return;/*from   w  ww  .j  a  va 2s  .c  om*/
    }
    float sclSum = 0;
    while (sclSum < .7f * mySize * mySize) {
        float spdAngle = PtmMath.rnd(180);
        Vector2 spd = new Vector2();
        PtmMath.fromAl(spd, spdAngle, PtmMath.rnd(0, .5f) * MAX_SPLIT_SPD);
        spd.add(mySpd);
        Vector2 newPos = new Vector2();
        PtmMath.fromAl(newPos, spdAngle, PtmMath.rnd(0, mySize / 2));
        newPos.add(myPos);
        float sz = mySize * PtmMath.rnd(.25f, .5f);
        Asteroid a = game.getAsteroidBuilder().buildNew(game, newPos, spd, sz, myRemoveController);
        game.getObjMan().addObjDelayed(a);
        sclSum += a.mySize * a.mySize;
    }
    float thrMoney = mySize * 40f * PtmMath.rnd(.3f, 1);
    List<MoneyItem> moneyItems = game.getItemMan().moneyToItems(thrMoney);
    for (MoneyItem mi : moneyItems) {
        throwLoot(game, mi);
    }
}

From source file:com.tnf.ptm.entities.asteroid.Asteroid.java

License:Apache License

private void throwLoot(PtmGame game, PtmItem item) {
    float spdAngle = PtmMath.rnd(180);
    Vector2 lootSpd = new Vector2();
    PtmMath.fromAl(lootSpd, spdAngle, PtmMath.rnd(0, Loot.MAX_SPD));
    lootSpd.add(mySpd);
    Vector2 pos = new Vector2();
    PtmMath.fromAl(pos, spdAngle, PtmMath.rnd(0, mySize / 2));
    pos.add(myPos);//  w  w w . j  a va  2 s  .com
    Loot l = game.getLootBuilder().build(game, pos, item, lootSpd, Loot.MAX_LIFE, PtmMath.rnd(Loot.MAX_ROT_SPD),
            null);
    game.getObjMan().addObjDelayed(l);
}

From source file:com.tnf.ptm.entities.gun.PtmGun.java

License:Apache License

public void update(ItemContainer ic, PtmGame game, float gunAngle, PtmObject creator, boolean shouldShoot,
        Faction faction) {//  w  w  w .  j  av  a  2s .  co m
    float baseAngle = creator.getAngle();
    Vector2 basePos = creator.getPosition();
    float gunRelAngle = gunAngle - baseAngle;
    mySprite.relAngle = gunRelAngle;
    Vector2 muzzleRelPos = PtmMath.fromAl(gunRelAngle, myItem.config.gunLength);
    muzzleRelPos.add(myRelPos);
    if (myLightSrc != null) {
        myLightSrc.setRelPos(muzzleRelPos);
    }
    Vector2 muzzlePos = PtmMath.toWorld(muzzleRelPos, baseAngle, basePos);
    PtmMath.free(muzzleRelPos);

    float ts = game.getTimeStep();
    if (myItem.ammo <= 0 && myItem.reloadAwait <= 0) {
        if (myItem.config.clipConf.infinite
                || ic != null && ic.tryConsumeItem(myItem.config.clipConf.example)) {
            myItem.reloadAwait = myItem.config.reloadTime + .0001f;
            game.getSoundManager().play(game, myItem.config.reloadSound, null, creator);
        }
    } else if (myItem.reloadAwait > 0) {
        myItem.reloadAwait -= ts;
        if (myItem.reloadAwait <= 0) {
            myItem.ammo = myItem.config.clipConf.size;
        }
    }

    if (myCoolDown > 0) {
        myCoolDown -= ts;
    }

    boolean shot = shouldShoot && myCoolDown <= 0 && myItem.ammo > 0;
    if (shot) {
        Vector2 gunSpd = creator.getSpd();
        shoot(gunSpd, game, gunAngle, muzzlePos, faction, creator);
    } else {
        myCurrAngleVar = PtmMath.approach(myCurrAngleVar, myItem.config.minAngleVar,
                myItem.config.angleVarDamp * ts);
    }
    if (myLightSrc != null) {
        myLightSrc.update(shot, baseAngle, game);
    }
    PtmMath.free(muzzlePos);
}

From source file:com.tnf.ptm.entities.item.Loot.java

License:Apache License

public void pickedUp(PtmGame game, PtmShip ship) {
    myLife = 0;// w w  w.  j a  v  a 2s  . c  o m
    Vector2 spd = new Vector2(ship.getPosition());
    spd.sub(myPos);
    float fadeTime = .25f;
    spd.scl(1 / fadeTime);
    spd.add(ship.getSpd());
    game.getPartMan().blip(game, myPos, myAngle, myItem.getItemType().sz, fadeTime, spd, myItem.getIcon(game));
    game.getSoundManager().play(game, myItem.getItemType().pickUpSound, null, this);
}

From source file:com.tnf.ptm.entities.maze.MazeBuilder.java

License:Apache License

private Vector2 cellPos(int col, int row, float xOffset, float yOffset) {
    Vector2 res = new Vector2((col - mySz / 2) * TILE_SZ + xOffset, (row - mySz / 2) * TILE_SZ + yOffset);
    PtmMath.rotate(res, myMazeAngle);/*from w  w w . j a v  a2 s  .co m*/
    res.add(myMazePos);
    return res;
}

From source file:com.tnf.ptm.entities.maze.MazeBuilder.java

License:Apache License

private void buildEnemies(PtmGame game, Maze maze, MazeLayout layout) {
    MazeConfig config = maze.getConfig();
    float dist = maze.getRadius() - BORDER / 2;
    float circleLen = dist * PtmMath.PI * 2;
    for (ShipConfig e : config.outerEnemies) {
        int count = (int) (e.density * circleLen);
        for (int i = 0; i < count; i++) {
            Vector2 pos = new Vector2();
            PtmMath.fromAl(pos, PtmMath.rnd(180), dist);
            pos.add(myMazePos);
            buildEnemy(pos, game, e, false);
        }/*  www .jav a  2 s.  c om*/
    }

    boolean[][] occupiedCells = new boolean[mySz][mySz];
    occupiedCells[mySz / 2][mySz / 2] = true;
    for (ShipConfig e : config.innerEnemies) {
        int count = (int) (e.density * myInnerRad * myInnerRad * PtmMath.PI);
        for (int i = 0; i < count; i++) {
            Vector2 pos = getFreeCellPos(occupiedCells);
            if (pos != null) {
                buildEnemy(pos, game, e, true);
            }
        }
    }
    ShipConfig bossConfig = PtmMath.elemRnd(config.bosses);
    Vector2 pos = cellPos(mySz / 2, mySz / 2, 0f, 0f);
    buildEnemy(pos, game, bossConfig, true);
}

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

License:Apache License

@Bound
public Vector2 getAdjustedEffectSpd(Vector2 pos, Vector2 spd) {
    Vector2 r = PtmMath.getVec(spd);
    if (myConfig.skyConfig == null) {
        return r;
    }// w w w  .  ja v a 2  s  .  c o m
    Vector2 up = PtmMath.distVec(myPos, pos);
    float dst = up.len();
    if (dst == 0 || getFullHeight() < dst) {
        PtmMath.free(up);
        return r;
    }
    float smokeConst = 1.2f * myGravConst;
    if (dst < myGroundHeight) {
        up.scl(smokeConst / dst / myGroundHeight / myGroundHeight);
        r.set(up);
        PtmMath.free(up);
        return r;
    }
    float spdPerc = (dst - myGroundHeight) / Const.ATM_HEIGHT;
    r.scl(spdPerc);
    up.scl(smokeConst / dst / dst / dst);
    r.add(up);
    PtmMath.free(up);
    return r;
}