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:org.destinationsol.game.MapDrawer.java

License:Apache License

private void drawNpGround(GameDrawer drawer, SolGame game, float viewDist, Planet np, Vector2 camPos) {
    ObjectManager objectManager = game.getObjMan();
    List<SolObject> objs = objectManager.getObjs();
    for (int i1 = 0, objsSize = objs.size(); i1 < objsSize; i1++) {
        SolObject o = objs.get(i1);/*  w  w w .ja  va 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:org.destinationsol.game.maze.Maze.java

License:Apache License

public void update(SolGame game) {
    SolCam cam = game.getCam();/*from www. j a  va2s  .  co  m*/
    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:org.destinationsol.game.maze.MazeBuilder.java

License:Apache License

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

From source file:org.destinationsol.game.planet.Planet.java

License:Apache License

public void update(SolGame game) {
    float ts = game.getTimeStep();
    myAngleToSys += myToSysRotSpd * ts;/*from  w ww .j a  v a 2  s .  c o  m*/
    myAngle += myRotSpd * ts;

    setSecondaryParams();
    Vector2 camPos = game.getCam().getPos();
    if (!myObjsCreated && camPos.dst(myPos) < getGroundHeight() + Const.MAX_SKY_HEIGHT_FROM_GROUND) {
        myMinGroundHeight = new PlanetObjectsBuilder().createPlanetObjs(game, this);
        fillLangingPlaces(game);
        myObjsCreated = true;
    }
}

From source file:org.destinationsol.game.planet.PlanetCoreSingleton.java

License:Apache License

public void draw(SolGame game, GameDrawer drawer) {
    SolCam cam = game.getCam();/*  ww w.  j  a va 2s.  c o  m*/
    Vector2 camPos = cam.getPos();
    Planet p = game.getPlanetMan().getNearestPlanet();
    Vector2 pPos = p.getPos();
    float toCamLen = camPos.dst(pPos);
    float vd = cam.getViewDist();
    float gh = p.getMinGroundHeight();
    if (toCamLen < gh + vd) {
        float sz = gh;
        drawer.draw(myTex, sz * 2, sz * 2, sz, sz, pPos.x, pPos.y, p.getAngle(), SolColor.W);
    }
}

From source file:org.destinationsol.game.planet.PlanetManager.java

License:Apache License

public Planet getNearestPlanet(Vector2 pos) {
    float minDst = Float.MAX_VALUE;
    Planet res = null;//from   w  ww  .  java  2 s.  c  o m
    for (int i = 0, myPlanetsSize = myPlanets.size(); i < myPlanetsSize; i++) {
        Planet p = myPlanets.get(i);
        float dst = pos.dst(p.getPos());
        if (dst < minDst) {
            minDst = dst;
            res = p;
        }
    }
    return res;
}

From source file:org.destinationsol.game.planet.PlanetManager.java

License:Apache License

private void applyGrav(SolGame game, SolSystem nearestSys) {
    float npGh = myNearestPlanet.getGroundHeight();
    float npFh = myNearestPlanet.getFullHeight();
    float npMinH = myNearestPlanet.getMinGroundHeight();
    Vector2 npPos = myNearestPlanet.getPos();
    Vector2 sysPos = nearestSys.getPos();
    float npGravConst = myNearestPlanet.getGravConst();

    List<SolObject> objs = game.getObjMan().getObjs();
    for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
        SolObject obj = objs.get(i);//from w w w .j ava  2  s  . c om
        if (!obj.receivesGravity())
            continue;

        Vector2 objPos = obj.getPosition();
        float minDist;
        Vector2 srcPos;
        float gravConst;
        boolean onPlanet;
        float toNp = npPos.dst(objPos);
        float toSys = sysPos.dst(objPos);
        if (toNp < npFh) {
            if (recoverObj(obj, toNp, npMinH))
                continue;
            minDist = npGh;
            srcPos = npPos;
            gravConst = npGravConst;
            onPlanet = true;
        } else if (toSys < Const.SUN_RADIUS) {
            minDist = SunSingleton.SUN_HOT_RAD;
            srcPos = sysPos;
            gravConst = SunSingleton.GRAV_CONST;
            onPlanet = false;
        } else {
            continue;
        }

        Vector2 grav = SolMath.getVec(srcPos);
        grav.sub(objPos);
        float len = grav.len();
        grav.nor();
        if (len < minDist) {
            len = minDist;
        }
        float g = gravConst / len / len;
        grav.scl(g);
        obj.receiveForce(grav, game, true);
        SolMath.free(grav);
        if (!onPlanet) {
            mySunSingleton.doDmg(game, obj, toSys);
        }
    }

}

From source file:org.destinationsol.game.planet.PlanetManager.java

License:Apache License

public SolSystem getNearestSystem(Vector2 pos) {
    float minDst = Float.MAX_VALUE;
    SolSystem res = null;//from w ww. j a v a2  s.c  o m
    for (int i = 0, mySystemsSize = mySystems.size(); i < mySystemsSize; i++) {
        SolSystem s = mySystems.get(i);
        float dst = pos.dst(s.getPos());
        if (dst < minDst) {
            minDst = dst;
            res = s;
        }
    }
    return res;
}

From source file:org.destinationsol.game.planet.PlanetManager.java

License:Apache License

public Maze getNearestMaze(Vector2 pos) {
    float minDst = Float.MAX_VALUE;
    Maze res = null;/*w w w.ja va 2 s .  co m*/
    for (int i = 0, myMazesSize = myMazes.size(); i < myMazesSize; i++) {
        Maze m = myMazes.get(i);
        float dst = pos.dst(m.getPos());
        if (dst < minDst) {
            minDst = dst;
            res = m;
        }
    }
    return res;
}

From source file:org.destinationsol.game.planet.PlanetObjectsBuilder.java

License:Apache License

public void createDeco(SolGame game, Planet planet) {
    float groundHeight = planet.getGroundHeight();
    Vector2 planetPos = planet.getPos();
    float planetAngle = planet.getAngle();
    Map<Vector2, List<Dra>> collector = new HashMap<Vector2, List<Dra>>();
    PlanetConfig config = planet.getConfig();
    for (DecoConfig dc : config.deco) {
        addDeco0(game, groundHeight, planetPos, collector, dc);
    }/* ww  w.  j  a v a 2  s.c o m*/

    for (Map.Entry<Vector2, List<Dra>> e : collector.entrySet()) {
        Vector2 packPos = e.getKey();
        List<Dra> ss = e.getValue();
        float packAngle = SolMath.angle(planetPos, packPos, true) - planetAngle;
        float packDist = packPos.dst(planetPos);
        FarPlanetSprites ps = new FarPlanetSprites(planet, packAngle, packDist, ss, 0);
        game.getObjMan().addFarObjNow(ps);
    }
}