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

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

Introduction

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

Prototype

@Override
    public float dst(Vector2 v) 

Source Link

Usage

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

License:Apache License

private void drawMazes(GameDrawer drawer, PtmGame game, float viewDist, Planet np, Vector2 camPos,
        float heroDmgCap, float camAngle) {
    ArrayList<Maze> mazes = game.getPlanetMan().getMazes();
    for (int i = 0, mazesSize = mazes.size(); i < mazesSize; i++) {
        Maze maze = mazes.get(i);//from w  ww  . ja v a  2 s .  c  o  m
        Vector2 mazePos = maze.getPos();
        float outerRad = maze.getRadius();
        float rad = outerRad - MazeBuilder.BORDER;
        if (viewDist < camPos.dst(mazePos) - rad) {
            continue;
        }
        drawer.draw(myMazeTex, 2 * rad, 2 * rad, rad, rad, mazePos.x, mazePos.y, 45, PtmColor.WHITE);
        if (HardnessCalc.isDangerous(heroDmgCap, maze.getDps())) {
            drawAreaDanger(drawer, outerRad, mazePos, 1, camAngle);
        }
    }

}

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  . j  a va2 s .co m*/
    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.MapDrawer.java

License:Apache License

private void drawIcons(GameDrawer drawer, PtmGame game, float iconSz, float viewDist,
        FactionManager factionManager, PtmShip hero, Vector2 camPos, float heroDmgCap) {
    List<PtmObject> objs = game.getObjMan().getObjs();
    for (int i1 = 0, objsSize = objs.size(); i1 < objsSize; i1++) {
        PtmObject o = objs.get(i1);//w  ww  . java2s.  co  m
        Vector2 oPos = o.getPosition();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        if ((o instanceof PtmShip)) {
            PtmShip ship = (PtmShip) o;
            String hint = ship.getPilot().getMapHint();
            if (hint == null && !DebugOptions.DETAILED_MAP) {
                continue;
            }
            drawObjIcon(iconSz, oPos, ship.getAngle(), factionManager, hero, ship.getPilot().getFaction(),
                    heroDmgCap, o, ship.getHull().config.getIcon(), drawer);
        }
        if ((o instanceof StarPort)) {
            StarPort sp = (StarPort) o;
            drawStarPortIcon(drawer, iconSz, sp.getFrom(), sp.getTo());
        }
        // Fix for when the player is in hyper. Hero is null and replaced in ObjMan with a StarPort.Transcendent
        if ((o instanceof StarPort.Transcendent)) {
            StarPort.Transcendent t = (StarPort.Transcendent) o;
            if (t.getShip().getPilot().isPlayer()) {
                FarShip ship = game.getTranscendentHero().getShip();
                drawObjIcon(iconSz, oPos, t.getAngle(), factionManager, hero, ship.getPilot().getFaction(),
                        heroDmgCap, o, ship.getHullConfig().getIcon(), drawer);
            }

        }
    }

    List<FarShip> farShips = game.getObjMan().getFarShips();
    for (int i = 0, sz = farShips.size(); i < sz; i++) {
        FarShip ship = farShips.get(i);
        Vector2 oPos = ship.getPos();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        String hint = ship.getPilot().getMapHint();
        if (hint == null && !DebugOptions.DETAILED_MAP) {
            continue;
        }
        drawObjIcon(iconSz, oPos, ship.getAngle(), factionManager, hero, ship.getPilot().getFaction(),
                heroDmgCap, ship, ship.getHullConfig().getIcon(), drawer);
    }

    List<StarPort.MyFar> farPorts = game.getObjMan().getFarPorts();
    for (int i = 0, sz = farPorts.size(); i < sz; i++) {
        StarPort.MyFar sp = farPorts.get(i);
        drawStarPortIcon(drawer, iconSz, sp.getFrom(), sp.getTo());
    }
    BeaconHandler bh = game.getBeaconHandler();
    BeaconHandler.Action bhAction = bh.getCurrAction();
    if (bhAction != null) {
        Vector2 beaconPos = bh.getPos();
        TextureRegion icon = myBeaconMoveTex;
        if (bhAction == BeaconHandler.Action.ATTACK) {
            icon = myBeaconAttackTex;
        } else if (bhAction == BeaconHandler.Action.FOLLOW) {
            icon = myBeaconFollowTex;
        }
        float beaconSz = iconSz * 1.5f;
        //      drawer.draw(icon, beaconSz, beaconSz, beaconSz/2, beaconSz/2, beaconPos.x, beaconPos.y, 0, PtmColor.WHITE); interleaving
    }
}

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

License:Apache License

private void drawStarNodes(GameDrawer drawer, PtmGame game, float viewDist, Vector2 camPos, float starNodeW) {
    List<PtmObject> objs = game.getObjMan().getObjs();
    for (int i1 = 0, objsSize = objs.size(); i1 < objsSize; i1++) {
        PtmObject o = objs.get(i1);//from   w w w . j  a  v  a  2  s .  c  o m
        if (!(o instanceof StarPort)) {
            continue;
        }
        Vector2 oPos = o.getPosition();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        StarPort sp = (StarPort) o;
        drawStarNode(drawer, sp.getFrom(), sp.getTo(), starNodeW);
    }

    List<StarPort.MyFar> farPorts = game.getObjMan().getFarPorts();
    for (int i = 0, sz = farPorts.size(); i < sz; i++) {
        StarPort.MyFar sp = farPorts.get(i);
        Vector2 oPos = sp.getPos();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        if (!sp.isSecondary()) {
            drawStarNode(drawer, sp.getFrom(), sp.getTo(), starNodeW);
        }
    }
}

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

License:Apache License

private void drawNpGround(GameDrawer drawer, PtmGame game, float viewDist, Planet np, Vector2 camPos) {
    ObjectManager objectManager = game.getObjMan();
    List<PtmObject> objs = objectManager.getObjs();
    for (int i1 = 0, objsSize = objs.size(); i1 < objsSize; i1++) {
        PtmObject o = objs.get(i1);/*from  w  ww. j  a v  a 2s  .c  o  m*/
        if (!(o instanceof TileObject)) {
            continue;
        }
        TileObject to = (TileObject) o;
        if (to.getPlanet() != np) {
            continue;
        }
        Vector2 oPos = o.getPosition();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        float sz = to.getSz();
        drawPlanetTile(to.getTile(), sz, drawer, oPos, to.getAngle());
    }

    List<FarObjData> farObjs = objectManager.getFarObjs();
    for (int i = 0, farObjsSize = farObjs.size(); i < farObjsSize; i++) {
        FarObjData fod = farObjs.get(i);
        FarObj o = fod.fo;
        if (!(o instanceof FarTileObject)) {
            continue;
        }
        FarTileObject to = (FarTileObject) o;
        if (to.getPlanet() != np) {
            continue;
        }
        Vector2 oPos = o.getPos();
        if (viewDist < camPos.dst(oPos)) {
            continue;
        }
        float sz = to.getSz();
        drawPlanetTile(to.getTile(), sz, drawer, oPos, to.getAngle());
    }
}

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

License:Apache License

public boolean isPlaceEmpty(Vector2 pos, boolean considerPlanets) {
    Planet np = myPlanetManager.getNearestPlanet(pos);
    if (considerPlanets) {
        boolean inPlanet = np.getPos().dst(pos) < np.getFullHeight();
        if (inPlanet) {
            return false;
        }// www .j  av a2 s .  c  o  m
    }
    PtmSystem ns = myPlanetManager.getNearestSystem(pos);
    if (ns.getPos().dst(pos) < SunSingleton.SUN_HOT_RAD) {
        return false;
    }
    List<PtmObject> objs = myObjectManager.getObjs();
    for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
        PtmObject o = objs.get(i);
        if (!o.hasBody()) {
            continue;
        }
        if (pos.dst(o.getPosition()) < myObjectManager.getRadius(o)) {
            return false;
        }
    }
    List<FarObjData> farObjs = myObjectManager.getFarObjs();
    for (int i = 0, farObjsSize = farObjs.size(); i < farObjsSize; i++) {
        FarObjData fod = farObjs.get(i);
        FarObj o = fod.fo;
        if (!o.hasBody()) {
            continue;
        }
        if (pos.dst(o.getPos()) < o.getRadius()) {
            return false;
        }
    }
    return true;
}

From source file:com.tnf.ptm.entities.chunk.ChunkFiller.java

License:Apache License

private void fillForSys(PtmGame game, Vector2 chCenter, RemoveController remover, PtmSystem sys) {
    SysConfig conf = sys.getConfig();//from w  w w . j a va 2  s. co  m
    Vector2 mainStationPos = game.getGalaxyFiller().getMainStationPos();
    Vector2 startPos = mainStationPos == null ? new Vector2() : mainStationPos;
    float dst = chCenter.dst(startPos);
    if (Const.CHUNK_SIZE < dst) {
        fillAsteroids(game, remover, false, chCenter);
        ArrayList<ShipConfig> enemies = sys.getPos().dst(chCenter) < sys.getInnerRad() ? conf.innerTempEnemies
                : conf.tempEnemies;
        for (ShipConfig enemyConf : enemies) {
            fillEnemies(game, remover, enemyConf, chCenter);
        }
    }
}

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

License:Apache License

public void update(ItemContainer ic, PtmGame game, float shipAngle, PtmShip creator, boolean shouldShoot,
        PtmShip nearestEnemy, Faction faction) {
    if (myGun == null) {
        return;/*  w w  w  .  j a  v a2s . co m*/
    }
    if (!ic.contains(myGun.getItem())) {
        setGun(game, creator, null, false, 0);
        return;
    }

    if (creator.getHull().config.getType() != HullConfig.Type.STATION) {
        myRelGunAngle = 0;
    }
    myDetected = false;
    if (!myFixed && nearestEnemy != null) {
        Vector2 creatorPos = creator.getPosition();
        Vector2 nePos = nearestEnemy.getPosition();
        float dst = creatorPos.dst(nePos) - creator.getHull().config.getApproxRadius()
                - nearestEnemy.getHull().config.getApproxRadius();
        float detDst = game.getPlanetMan().getNearestPlanet().isNearGround(creatorPos) ? Const.AUTO_SHOOT_GROUND
                : Const.AUTO_SHOOT_SPACE;
        if (dst < detDst) {
            Vector2 mountPos = PtmMath.toWorld(myRelPos, shipAngle, creatorPos);
            boolean player = creator.getPilot().isPlayer();
            float shootAngle = Shooter.calcShootAngle(mountPos, creator.getSpd(), nePos, nearestEnemy.getSpd(),
                    myGun.getConfig().clipConf.projConfig.spdLen, player);
            if (shootAngle == shootAngle) {
                myRelGunAngle = shootAngle - shipAngle;
                myDetected = true;
                if (player) {
                    game.getMountDetectDrawer().setNe(nearestEnemy);
                }
            }
            PtmMath.free(mountPos);
        }
    }

    float gunAngle = shipAngle + myRelGunAngle;
    myGun.update(ic, game, gunAngle, creator, shouldShoot, faction);
}

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

License:Apache License

public void update(PtmGame game) {
    PtmCam cam = game.getCam();//from w  ww .  j  a va  2  s  .c  om
    Vector2 camPos = cam.getPos();
    if (!myObjsCreated && camPos.dst(myPos) < myRadius + Const.CAM_VIEW_DIST_JOURNEY * 2) {
        new MazeBuilder().build(game, this);
        myObjsCreated = true;
    }
}

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

License:Apache License

private Vector2 getFreeCellPos(boolean[][] occupiedCells) {
    for (int i = 0; i < 10; i++) {
        int col = PtmMath.intRnd(mySz);
        int row = PtmMath.intRnd(mySz);
        if (occupiedCells[col][row]) {
            continue;
        }//from   w  w w  .  ja v a 2s .c o m
        Vector2 pos = cellPos(col, row, 0f, 0f);
        if (.8f * myInnerRad < pos.dst(myMazePos)) {
            continue;
        }
        occupiedCells[col][row] = true;
        return pos;
    }
    return null;
}