List of usage examples for com.badlogic.gdx.math Vector2 scl
@Override
public Vector2 scl(Vector2 v)
From source file:org.destinationsol.game.planet.PlanetObjectsBuilder.java
License:Apache License
public FarShip buildGroundShip(SolGame 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 w w w . ja va 2s. c o m*/ 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); SolMath.toWorld(pos, pos, planet.getAngle(), planet.getPos(), false); Vector2 toPlanet = SolMath.getVec(planet.getPos()).sub(pos); float angle = SolMath.angle(toPlanet) - 180; if (station) angle += 90; Vector2 spd = new Vector2(toPlanet).nor(); SolMath.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:org.destinationsol.game.planet.TileObjBuilder.java
License:Apache License
private Body buildBody(SolGame 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; SolMath.fromAl(def.position, toPlanetAngle, dist, true); def.position.add(planet.getPos());// www.j a v a2 s . c o m def.angle = (toPlanetAngle + 90) * SolMath.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:org.destinationsol.game.planet.TileObject.java
License:Apache License
@Override public void update(SolGame game) { setDependentParams();/* w w w . j a va 2s . c om*/ if (myBody != null) { float ts = game.getTimeStep(); Vector2 spd = SolMath.getVec(myPos); spd.sub(myBody.getPosition()); spd.scl(1f / ts); myBody.setLinearVelocity(spd); SolMath.free(spd); float bodyAngle = myBody.getAngle() * SolMath.radDeg; float av = SolMath.norm(myAngle - bodyAngle) * SolMath.degRad / ts; myBody.setAngularVelocity(av); } }
From source file:org.destinationsol.game.projectile.PointProjectileBody.java
License:Apache License
@Override public void update(SolGame game) { if (myAcc > 0 && SolMath.canAccelerate(myAcc, mySpd)) { float spdLen = mySpd.len(); if (spdLen < Const.MAX_MOVE_SPD) { mySpd.scl((spdLen + myAcc) / spdLen); }// w w w .j a v a2s. c o m } Vector2 prevPos = SolMath.getVec(myPos); Vector2 diff = SolMath.getVec(mySpd); diff.scl(game.getTimeStep()); myPos.add(diff); SolMath.free(diff); game.getObjMan().getWorld().rayCast(myRayBack, prevPos, myPos); SolMath.free(prevPos); }
From source file:org.destinationsol.game.projectile.PointProjectileBody.java
License:Apache License
@Override public void receiveForce(Vector2 force, SolGame game, boolean acc) { force.scl(game.getTimeStep()); if (!acc)//from w w w .j av a 2 s . c om force.scl(10f); mySpd.add(force); }
From source file:org.destinationsol.game.ship.ForceBeacon.java
License:Apache License
public static SolShip pullShips(SolGame game, SolObject owner, Vector2 ownPos, Vector2 ownSpd, Faction faction, float maxPullDist) { SolShip res = null;//from w w w . j a v a 2s . c o m float minLen = Float.MAX_VALUE; List<SolObject> objs = game.getObjMan().getObjs(); for (int i = 0, objsSize = objs.size(); i < objsSize; i++) { SolObject o = objs.get(i); if (o == owner) continue; if (!(o instanceof SolShip)) continue; SolShip ship = (SolShip) o; Pilot pilot = ship.getPilot(); if (pilot.isUp() || pilot.isLeft() || pilot.isRight()) continue; if (game.getFactionMan().areEnemies(faction, pilot.getFaction())) continue; Vector2 toMe = SolMath.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.getSoundMan().play(game, game.getSpecialSounds().forceBeaconWork, null, ship); if (toMeLen < minLen) { res = ship; minLen = toMeLen; } } SolMath.free(toMe); } return res; }
From source file:org.destinationsol.game.ship.hulls.Hull.java
License:Apache License
public void update(SolGame game, ItemContainer container, Pilot provider, SolShip ship, SolShip nearestEnemy) { setParamsFromBody();/*from ww w . java 2 s . c o m*/ 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 = SolMath.getVec(); myPlanetBind.setDiff(spd, myPos, true); float fps = 1 / game.getTimeStep(); spd.scl(fps); myBody.setLinearVelocity(spd); SolMath.free(spd); float angleDiff = myPlanetBind.getDesiredAngle() - myAngle; myBody.setAngularVelocity(angleDiff * SolMath.degRad * fps); } }
From source file:org.destinationsol.game.ship.KnockBack.java
License:Apache License
@Override public boolean update(SolGame game, SolShip owner, boolean tryToUse) { if (!tryToUse) return false; Vector2 ownerPos = owner.getPosition(); for (SolObject 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 = SolMath.distVec(ownerPos, oPos); float accLen = myConfig.force * perc; toO.scl(accLen / dst); o.receiveForce(toO, game, false); SolMath.free(toO);//from www . j a va2 s . c om } 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:org.destinationsol.game.ship.SolShip.java
License:Apache License
@Override public void receiveForce(Vector2 force, SolGame game, boolean acc) { Body body = myHull.getBody();/* ww w .j av a2 s . com*/ if (acc) { force.scl(myHull.getMass()); } body.applyForceToCenter(force, true); }
From source file:org.destinationsol.game.SolCam.java
License:Apache License
public void update(SolGame game) { float desiredVd = Const.CAM_VIEW_DIST_GROUND; float life = 0; SolShip hero = game.getHero();/* w ww. ja v a 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 { desiredVd = Const.CAM_VIEW_DIST_SPACE; 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 = SolMath.getVec(hero.getSpd()); moveDiff.scl(ts); myPos.add(moveDiff); SolMath.free(moveDiff); float moveSpd = MOVE_SPD * ts; myPos.x = SolMath.approach(myPos.x, heroPos.x, moveSpd); myPos.y = SolMath.approach(myPos.y, heroPos.y, moveSpd); } life = hero.getLife(); float spd = hero.getSpd().len(); desiredVd = Const.CAM_VIEW_DIST_SPACE; Planet np = game.getPlanetMan().getNearestPlanet(myPos); if (np.getFullHeight() < np.getPos().dst(myPos) && MAX_ZOOM_SPD < spd) { desiredVd = Const.CAM_VIEW_DIST_JOURNEY; } else if (np.isNearGround(myPos) && spd < MED_ZOOM_SPD) { desiredVd = Const.CAM_VIEW_DIST_GROUND; } desiredVd += hero.getHull().config.getApproxRadius(); } if (life < myPrevHeroLife) { float shakeDiff = .1f * MAX_SHAKE * (myPrevHeroLife - life); myShake = SolMath.approach(myShake, MAX_SHAKE, shakeDiff); } else { myShake = SolMath.approach(myShake, 0, SHAKE_DAMP * ts); } myPrevHeroLife = life; Vector2 pos = SolMath.fromAl(SolMath.rnd(180), myShake); pos.add(myPos); applyPos(pos.x, pos.y); SolMath.free(pos); float desiredAngle = myCamRotStrategy.getRotation(myPos, game); float rotSpd = CAM_ROT_SPD * ts; myAngle = SolMath.approachAngle(myAngle, desiredAngle, rotSpd); applyAngle(); float desiredZoom = calcZoom(desiredVd); myZoom = SolMath.approach(myZoom, desiredZoom, ZOOM_CHG_SPD * ts); applyZoom(game.getMapDrawer()); myCam.update(); }