List of usage examples for com.badlogic.gdx.math Vector2 scl
@Override
public Vector2 scl(Vector2 v)
From source file:com.tnf.ptm.entities.projectile.PointProjectileBody.java
License:Apache License
@Override public void receiveForce(Vector2 force, PtmGame game, boolean acc) { force.scl(game.getTimeStep()); if (!acc) {/*www .ja v a2s. c o m*/ force.scl(10f); } mySpd.add(force); }
From source file:com.tnf.ptm.entities.ship.ForceBeacon.java
License:Apache License
public static PtmShip pullShips(PtmGame game, PtmObject owner, Vector2 ownPos, Vector2 ownSpd, Faction faction, float maxPullDist) { PtmShip res = null;/*from w w w . j ava2 s .c om*/ float minLen = Float.MAX_VALUE; List<PtmObject> objs = game.getObjMan().getObjs(); for (int i = 0, objsSize = objs.size(); i < objsSize; i++) { PtmObject o = objs.get(i); if (o == owner) { continue; } if (!(o instanceof PtmShip)) { continue; } PtmShip ship = (PtmShip) o; Pilot pilot = ship.getPilot(); if (pilot.isUp() || pilot.isLeft() || pilot.isRight()) { continue; } if (game.getFactionMan().areEnemies(faction, pilot.getFaction())) { continue; } Vector2 toMe = PtmMath.distVec(ship.getPosition(), ownPos); float toMeLen = toMe.len(); if (toMeLen < maxPullDist) { if (toMeLen > 1) { toMe.scl(1 / toMeLen); } if (ownSpd != null) { toMe.add(ownSpd); } ship.getHull().getBody().setLinearVelocity(toMe); game.getSoundManager().play(game, game.getSpecialSounds().forceBeaconWork, null, ship); if (toMeLen < minLen) { res = ship; minLen = toMeLen; } } PtmMath.free(toMe); } return res; }
From source file:com.tnf.ptm.entities.ship.hulls.Hull.java
License:Apache License
public void update(PtmGame game, ItemContainer container, Pilot provider, PtmShip ship, PtmShip nearestEnemy) { setParamsFromBody();/*from w w w.j a v a2 s . c om*/ boolean controlsEnabled = ship.isControlsEnabled(); if (myEngine != null) { if (true || container.contains(myEngine.getItem())) { myEngine.update(myAngle, game, provider, myBody, mySpd, ship, controlsEnabled, myMass); } else { setEngine(game, ship, null); } } Faction faction = ship.getPilot().getFaction(); myGunMount1.update(container, game, myAngle, ship, controlsEnabled && provider.isShoot(), nearestEnemy, faction); if (myGunMount2 != null) { myGunMount2.update(container, game, myAngle, ship, controlsEnabled && provider.isShoot2(), nearestEnemy, faction); } for (int i = 0, myLightSrcsSize = myLightSrcs.size(); i < myLightSrcsSize; i++) { LightSrc src = myLightSrcs.get(i); src.update(true, myAngle, game); } for (int i = 0, myBeaconsSize = myBeacons.size(); i < myBeaconsSize; i++) { ForceBeacon b = myBeacons.get(i); b.update(game, myPos, myAngle, ship); } for (int i = 0, myDoorsSize = myDoors.size(); i < myDoorsSize; i++) { Door door = myDoors.get(i); door.update(game, ship); } if (myPlanetBind != null) { Vector2 spd = PtmMath.getVec(); myPlanetBind.setDiff(spd, myPos, true); float fps = 1 / game.getTimeStep(); spd.scl(fps); myBody.setLinearVelocity(spd); PtmMath.free(spd); float angleDiff = myPlanetBind.getDesiredAngle() - myAngle; myBody.setAngularVelocity(angleDiff * PtmMath.degRad * fps); } }
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; }/* w w w . j a v a 2 s . c o m*/ 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.PtmShip.java
License:Apache License
@Override public void receiveForce(Vector2 force, PtmGame game, boolean acc) { Body body = myHull.getBody();/*from w w w. j a v a2 s . c o m*/ if (acc) { force.scl(myHull.getMass()); } body.applyForceToCenter(force, true); }
From source file:com.tnf.ptm.entities.StarPort.java
License:Apache License
private static Vector2 adjustDesiredPos(PtmGame game, StarPort myPort, Vector2 desired) { Vector2 newPos = desired;//from w w w .j a va2 s . com List<PtmObject> objs = game.getObjMan().getObjs(); for (PtmObject o : objs) { if (o instanceof StarPort && o != myPort) { StarPort sp = (StarPort) o; // Check if the positions overlap Vector2 fromPos = sp.getPosition(); Vector2 distVec = PtmMath.distVec(fromPos, desired); float distance = PtmMath.hypotenuse(distVec.x, distVec.y); if (distance <= (float) StarPort.SIZE) { distVec.scl((StarPort.SIZE + .5f) / distance); newPos = fromPos.cpy().add(distVec); Vector2 d2 = PtmMath.distVec(fromPos, newPos); PtmMath.free(d2); } PtmMath.free(distVec); } } return newPos; }
From source file:com.tnf.ptm.gfx.PtmCam.java
License:Apache License
public void update(PtmGame game) { float life = 0; PtmShip hero = game.getHero();//from w w w. ja va 2 s. c om float ts = game.getTimeStep(); if (hero == null) { StarPort.Transcendent trans = game.getTranscendentHero(); if (trans == null) { if (DebugOptions.DIRECT_CAM_CONTROL) { applyInput(game); } } else { myPos.set(trans.getPosition()); } } else { Vector2 heroPos = hero.getHull().getBody().getWorldCenter(); if (myZoom * VIEWPORT_HEIGHT < heroPos.dst(myPos)) { myPos.set(heroPos); game.getObjMan().resetDelays(); } else { Vector2 moveDiff = PtmMath.getVec(hero.getSpd()); moveDiff.scl(ts); myPos.add(moveDiff); PtmMath.free(moveDiff); float moveSpd = MOVE_SPD * ts; myPos.x = PtmMath.approach(myPos.x, heroPos.x, moveSpd); myPos.y = PtmMath.approach(myPos.y, heroPos.y, moveSpd); } life = hero.getLife(); } if (life < myPrevHeroLife) { float shakeDiff = .1f * MAX_SHAKE * (myPrevHeroLife - life); myShake = PtmMath.approach(myShake, MAX_SHAKE, shakeDiff); } else { myShake = PtmMath.approach(myShake, 0, SHAKE_DAMP * ts); } myPrevHeroLife = life; Vector2 pos = PtmMath.fromAl(PtmMath.rnd(180), myShake); pos.add(myPos); applyPos(pos.x, pos.y); PtmMath.free(pos); float desiredAngle = myCamRotStrategy.getRotation(myPos, game); float rotSpd = CAM_ROT_SPD * ts; myAngle = PtmMath.approachAngle(myAngle, desiredAngle, rotSpd); applyAngle(); updateMap(game); }
From source file:com.tnf.ptm.gfx.PtmCam.java
License:Apache License
private void applyInput(PtmGame game) { MainScreen s = game.getScreens().mainScreen; boolean d = s.isDown(); boolean u = s.isUp(); boolean l = s.isLeft(); boolean r = s.isRight(); Vector2 v = PtmMath.getVec(); if (l != r) { v.x = PtmMath.toInt(r);//from w w w. java 2s . c o m } if (d != u) { v.y = PtmMath.toInt(d); } v.scl(MOVE_SPD * game.getTimeStep()); PtmMath.rotate(v, myAngle); myPos.add(v); PtmMath.free(v); }
From source file:com.tnf.ptm.gfx.PtmCam.java
License:Apache License
public void drawDebug(GameDrawer drawer) { float hOver2 = VIEWPORT_HEIGHT * myZoom / 2; float wOver2 = hOver2 * drawer.r; Vector2 dr = PtmMath.getVec(wOver2, hOver2); PtmMath.rotate(dr, myAngle);/*from www . j a va 2 s.c o m*/ Vector2 dl = PtmMath.getVec(-wOver2, hOver2); PtmMath.rotate(dl, myAngle); Vector2 ul = PtmMath.getVec(dr); ul.scl(-1); Vector2 ur = PtmMath.getVec(dl); ur.scl(-1); dr.add(myPos); dl.add(myPos); ul.add(myPos); ur.add(myPos); float lw = getRealLineWidth(); drawer.drawLine(drawer.debugWhiteTex, dr, dl, PtmColor.WHITE, lw, false); drawer.drawLine(drawer.debugWhiteTex, dl, ul, PtmColor.WHITE, lw, false); drawer.drawLine(drawer.debugWhiteTex, ul, ur, PtmColor.WHITE, lw, false); drawer.drawLine(drawer.debugWhiteTex, ur, dr, PtmColor.WHITE, lw, false); PtmMath.free(dr); PtmMath.free(dl); PtmMath.free(ul); PtmMath.free(ur); }
From source file:com.tnf.ptm.handler.input.AiPilot.java
License:Apache License
@Override public void updateFar(PtmGame game, FarShip farShip) { Vector2 shipPos = farShip.getPos(); HullConfig hullConfig = farShip.getHullConfig(); float maxIdleDist = getMaxIdleDist(hullConfig); myDestProvider.update(game, shipPos, maxIdleDist, hullConfig, null); Vector2 dest = myDestProvider.getDest(); Vector2 spd = farShip.getSpd(); float angle = farShip.getAngle(); Engine engine = farShip.getEngine(); float ts = game.getTimeStep(); if (dest == null || engine == null) { if (myPlanetBind == null) { if (myBindAwait > 0) { myBindAwait -= ts;/*from ww w . ja va 2 s .c om*/ } else { myPlanetBind = PlanetBind.tryBind(game, shipPos, angle); myBindAwait = MAX_BIND_AWAIT; } } if (myPlanetBind != null) { myPlanetBind.setDiff(spd, shipPos, false); spd.scl(1 / ts); angle = myPlanetBind.getDesiredAngle(); } } else { float toDestLen = shipPos.dst(dest); float desiredAngle; float maxIdleDistHack = .05f; // to avoid StillGuards from getting stuck inside ground if (myDestProvider.shouldStopNearDest() && toDestLen < maxIdleDistHack) { spd.set(myDestProvider.getDestSpd()); desiredAngle = angle; // can be improved } else { desiredAngle = PtmMath.angle(shipPos, dest); if (myDestProvider.shouldAvoidBigObjs()) { desiredAngle = myMover.getBigObjAvoider().avoid(game, shipPos, dest, desiredAngle); } float desiredSpdLen = myDestProvider.getDesiredSpdLen(); float spdLenDiff = engine.getAcc() * ts; float spdLen = PtmMath.approach(spd.len(), desiredSpdLen, spdLenDiff); if (toDestLen < spdLen) { spdLen = toDestLen; } PtmMath.fromAl(spd, desiredAngle, spdLen); } angle = PtmMath.approachAngle(angle, desiredAngle, engine.getMaxRotSpd() * ts); } farShip.setSpd(spd); farShip.setAngle(angle); Vector2 newPos = PtmMath.getVec(spd); newPos.scl(ts); newPos.add(shipPos); farShip.setPos(newPos); PtmMath.free(newPos); }