List of usage examples for com.badlogic.gdx.math Vector2 scl
@Override
public Vector2 scl(Vector2 v)
From source file:com.tnf.ptm.entities.chunk.ChunkFiller.java
License:Apache License
/** * Fill the background of a given chunk with floating junk. * * @param game The {@link PtmGame} instance to work with * @param chunk The coordinates of the chunk * @param remover/*from w w w. java2s. c om*/ * @param farBg Determines which of the background layers should be filled. <code>true</code> fills the layers furthest away, <code>false</code> fills the closer one. */ public void fill(PtmGame game, Vector2 chunk, RemoveController remover, boolean farBg) { if (DebugOptions.NO_OBJS) { return; } // Determine the center of the chunk by multiplying the chunk coordinates with the chunk size and adding half a chunk's size Vector2 chCenter = new Vector2(chunk); chCenter.scl(Const.CHUNK_SIZE); chCenter.add(Const.CHUNK_SIZE / 2, Const.CHUNK_SIZE / 2); // Define the density multiplier for different layers of junk in the far background float[] densityMul = { 1 }; // Get the environment configuration SpaceEnvConfig conf = getConfig(game, chCenter, densityMul, remover, farBg); if (farBg) { fillFarJunk(game, chCenter, remover, DraLevel.FAR_DECO_3, conf, densityMul[0]); fillFarJunk(game, chCenter, remover, DraLevel.FAR_DECO_2, conf, densityMul[0]); fillFarJunk(game, chCenter, remover, DraLevel.FAR_DECO_1, conf, densityMul[0]); } else { fillDust(game, chCenter, remover); fillJunk(game, remover, conf, chCenter); } }
From source file:com.tnf.ptm.entities.item.Loot.java
License:Apache License
public void maybePulled(PtmShip ship, Vector2 pullerPos, float radius) { if (ship == myOwner) { return;// w w w . ja va 2 s. co m } Vector2 toPuller = PtmMath.getVec(pullerPos); toPuller.sub(getPosition()); float pullerDist = toPuller.len(); if (0 < pullerDist && pullerDist < radius) { toPuller.scl(PULL_DESIRED_SPD / pullerDist); Vector2 spd = myBody.getLinearVelocity(); Vector2 spdDiff = PtmMath.distVec(spd, toPuller); float spdDiffLen = spdDiff.len(); if (spdDiffLen > 0) { spdDiff.scl(PULL_FORCE / spdDiffLen); myBody.applyForceToCenter(spdDiff, true); } PtmMath.free(spdDiff); } PtmMath.free(toPuller); }
From source file:com.tnf.ptm.entities.item.Loot.java
License:Apache License
public void pickedUp(PtmGame game, PtmShip ship) { myLife = 0;/*ww w .ja v a2 s . 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.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; }/*from ww w . j a v a2 s. co 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; }
From source file:com.tnf.ptm.entities.planet.PlanetManager.java
License:Apache License
private void applyGrav(PtmGame game, PtmSystem 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<PtmObject> objs = game.getObjMan().getObjs(); for (PtmObject obj : objs) { if (!obj.receivesGravity()) { continue; }/*w ww . j a v a 2 s. co m*/ 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 = PtmMath.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); PtmMath.free(grav); if (!onPlanet) { mySunSingleton.doDmg(game, obj, toSys); } } }
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 . j a v a 2 s . c o m*/ 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.planet.PlanetObjectsBuilder.java
License:Apache License
public FarShip buildGroundShip(PtmGame game, Planet planet, ShipConfig ge, TradeConfig tc, Faction faction, ConsumedAngles takenAngles, String mapHint) { Vector2 pos = game.getPlanetMan().findFlatPlace(game, planet, takenAngles, ge.hull.getApproxRadius()); boolean station = ge.hull.getType() == HullConfig.Type.STATION; String ic = ge.items;/*from www .jav a 2 s . com*/ boolean hasRepairer; hasRepairer = faction == Faction.LAANI; int money = ge.money; float height = pos.len(); float aboveGround; if (station) { aboveGround = ge.hull.getSize() * .75f - ge.hull.getOrigin().y; } else { aboveGround = ge.hull.getSize(); } pos.scl((height + aboveGround) / height); PtmMath.toWorld(pos, pos, planet.getAngle(), planet.getPos(), false); Vector2 toPlanet = PtmMath.getVec(planet.getPos()).sub(pos); float angle = PtmMath.angle(toPlanet) - 180; if (station) { angle += 90; } Vector2 spd = new Vector2(toPlanet).nor(); PtmMath.free(toPlanet); Pilot provider = new AiPilot(new StillGuard(pos, game, ge), false, faction, true, mapHint, Const.AI_DET_DIST); return game.getShipBuilder().buildNewFar(game, pos, spd, angle, 0, provider, ic, ge.hull, null, hasRepairer, money, tc, true); }
From source file:com.tnf.ptm.entities.planet.TileObjBuilder.java
License:Apache License
private Body buildBody(PtmGame game, float toPlanetRelAngle, float dist, Tile tile, Planet planet, float spriteSz) { BodyDef def = new BodyDef(); def.type = BodyDef.BodyType.KinematicBody; float toPlanetAngle = planet.getAngle() + toPlanetRelAngle; PtmMath.fromAl(def.position, toPlanetAngle, dist, true); def.position.add(planet.getPos());/*from w ww. j a v a 2 s.c o m*/ def.angle = (toPlanetAngle + 90) * PtmMath.degRad; def.angularDamping = 0; Body body = game.getObjMan().getWorld().createBody(def); ChainShape shape = new ChainShape(); List<Vector2> points = new ArrayList<Vector2>(); for (Vector2 curr : tile.points) { Vector2 v = new Vector2(curr); v.scl(spriteSz); points.add(v); } Vector2[] v = points.toArray(new Vector2[] {}); shape.createLoop(v); Fixture f = body.createFixture(shape, 0); f.setFriction(Const.FRICTION); shape.dispose(); return body; }
From source file:com.tnf.ptm.entities.planet.TileObject.java
License:Apache License
@Override public void update(PtmGame game) { setDependentParams();//from w ww. j a v a 2 s . co m if (myBody != null) { float ts = game.getTimeStep(); Vector2 spd = PtmMath.getVec(myPos); spd.sub(myBody.getPosition()); spd.scl(1f / ts); myBody.setLinearVelocity(spd); PtmMath.free(spd); float bodyAngle = myBody.getAngle() * PtmMath.radDeg; float av = PtmMath.norm(myAngle - bodyAngle) * PtmMath.degRad / ts; myBody.setAngularVelocity(av); } }
From source file:com.tnf.ptm.entities.projectile.PointProjectileBody.java
License:Apache License
@Override public void update(PtmGame game) { if (myAcc > 0 && PtmMath.canAccelerate(myAcc, mySpd)) { float spdLen = mySpd.len(); if (spdLen < Const.MAX_MOVE_SPD) { mySpd.scl((spdLen + myAcc) / spdLen); }/*from ww w . j av a 2s . co m*/ } Vector2 prevPos = PtmMath.getVec(myPos); Vector2 diff = PtmMath.getVec(mySpd); diff.scl(game.getTimeStep()); myPos.add(diff); PtmMath.free(diff); game.getObjMan().getWorld().rayCast(myRayBack, prevPos, myPos); PtmMath.free(prevPos); }