List of usage examples for com.badlogic.gdx.math Vector2 dst
@Override public float dst(Vector2 v)
From source file:org.ams.testapps.paintandphysics.cardhouse.TurnCircle.java
License:Open Source License
/** Whether v is on the colored outline. */ public boolean isOnTurnCircle(Vector2 v) { if (!visible) return false; float dst = v.dst(position); boolean isOn = radius * zoom < dst && dst < (radius + width) * zoom; if (debug)/*from ww w .ja v a 2 s. co m*/ debug(isOn ? v + " is on circle." : v + " is not on circle."); return isOn; }
From source file:org.ams.testapps.paintandphysics.cardhouse.TurnCircle.java
License:Open Source License
/** Whether v is inside the colored outline. */ public boolean isInsideTurnCircle(Vector2 v) { if (!visible) return false; float dst = v.dst(position); boolean inside = dst < radius * zoom; if (debug)/*ww w.java2s.c om*/ debug(inside ? v + " is inside circle." : v + " is not inside circle."); return inside; }
From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java
License:Open Source License
/** * Checks whether a block should be locked into its final position. * Returns true when it is close enough to its final position and there * is a locked block under its final position. *///from w ww . jav a 2 s . co m private boolean allowedToLock(PPPolygon block) { int row = getRow(block); int column = getColumn(block); Vector2 currentPos = block.getPhysicsThing().getBody().getPosition(); Vector2 finalPosition = (Vector2) block.getUserData(); if (currentPos.dst(finalPosition) >= 0.04f) return false; return platformLevels.get(column) == row - 1; }
From source file:org.bladecoder.bladeengine.actions.GotoAction.java
License:Apache License
/** * If 'player' if far from 'actor', we bring it close. * If 'player' is closed from 'actor' do nothing. * // w ww . ja v a 2s . c o m * TODO: DOESN'T WORK NOW * * @param player * @param actor */ @SuppressWarnings("unused") private void goNear(SpriteActor player, Actor actor) { Rectangle rdest = actor.getBBox().getBoundingRectangle(); // Vector2 p0 = new Vector2(player.getSprite().getX(), // player.getSprite().getY()); Vector2 p0 = new Vector2(player.getX(), player.getY()); // calculamos el punto ms cercano al objeto Vector2 p1 = new Vector2(rdest.x, rdest.y); // izquierda Vector2 p2 = new Vector2(rdest.x + rdest.width, rdest.y); // derecha Vector2 p3 = new Vector2(rdest.x + rdest.width / 2, rdest.y); // centro float d1 = p0.dst(p1); float d2 = p0.dst(p2); float d3 = p0.dst(p3); Vector2 pf; if (d1 < d2 && d1 < d3) { pf = p1; } else if (d2 < d1 && d2 < d3) { pf = p2; } else { pf = p3; } player.goTo(pf, this); }
From source file:org.bladecoder.bladeengine.anim.WalkTween.java
License:Apache License
private void walkToNextStep(SpriteActor target) { Vector2 p0 = walkingPath.get(currentStep); Vector2 pf = walkingPath.get(currentStep + 1); target.startWalkFA(p0, pf);//from ww w .j a v a 2 s . com float segmentDuration = p0.dst(pf) / (EngineAssetManager.getInstance().getScale() * speed); if (currentStep == walkingPath.size() - 2 && (walkCb != null || walkCbSer != null)) { if (walkCbSer != null) { walkCb = ActionCallbackSerialization.find(walkCbSer); walkCbSer = null; } start(target, NO_REPEAT, 1, pf.x, pf.y, segmentDuration, walkCb); } else { start(target, NO_REPEAT, 1, pf.x, pf.y, segmentDuration, null); } }
From source file:org.destinationsol.game.chunk.ChunkFiller.java
License:Apache License
private void fillForSys(SolGame game, Vector2 chCenter, RemoveController remover, SolSystem sys) { SysConfig conf = sys.getConfig();/*from ww w. ja va 2 s .c om*/ 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:org.destinationsol.game.dra.DrasObject.java
License:Apache License
@Override public void update(SolGame game) { myMoveDiff.set(mySpd);/*from w ww.jav a 2 s . co m*/ float ts = game.getTimeStep(); myMoveDiff.scl(ts); myPos.add(myMoveDiff); if (myHideOnPlanet) { Planet np = game.getPlanetMan().getNearestPlanet(); Vector2 npPos = np.getPos(); float npgh = np.getGroundHeight(); DraMan draMan = game.getDraMan(); for (int i = 0, myDrasSize = myDras.size(); i < myDrasSize; i++) { Dra dra = myDras.get(i); if (!(dra instanceof RectSprite)) continue; if (!draMan.isInCam(dra)) continue; Vector2 draPos = dra.getPos(); float gradSz = .25f * Const.ATM_HEIGHT; float distPerc = (draPos.dst(npPos) - npgh - Const.ATM_HEIGHT) / gradSz; distPerc = SolMath.clamp(distPerc); ((RectSprite) dra).tint.a = distPerc; } } else if (myMaxFadeTime > 0) { myFadeTime -= ts; float tintPerc = myFadeTime / myMaxFadeTime; for (int i = 0, myDrasSize = myDras.size(); i < myDrasSize; i++) { Dra dra = myDras.get(i); if (!(dra instanceof RectSprite)) continue; RectSprite rs = (RectSprite) dra; rs.tint.a = SolMath.clamp(tintPerc * rs.baseAlpha); } } }
From source file:org.destinationsol.game.farBg.FarBackgroundManagerOld.java
License:Apache License
public void draw(GameDrawer drawer, SolCam cam, SolGame game) { Planet np = game.getPlanetMan().getNearestPlanet(); Vector2 camPos = cam.getPos(); float nebPerc = (camPos.dst(np.getPos()) - np.getGroundHeight()) / (4 * Const.ATM_HEIGHT); nebPerc = SolMath.clamp(nebPerc, 0, 1); myNebTint.a = nebPerc;// www .j a va 2s. c om float vd = cam.getViewDist(); drawer.draw(myNebTex, vd * 2, vd * 2, vd, vd, camPos.x, camPos.y, myNebAngle, myNebTint); for (int i = 0, myStarsSize = myStars.size(); i < myStarsSize; i++) { FarBgStar star = myStars.get(i); star.draw(drawer, vd, camPos, cam.getAngle()); } }
From source file:org.destinationsol.game.gun.GunMount.java
License:Apache License
public void update(ItemContainer ic, SolGame game, float shipAngle, SolShip creator, boolean shouldShoot, SolShip nearestEnemy, Faction faction) { if (myGun == null) return;// w w w.j av a 2 s . com 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 = SolMath.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); } SolMath.free(mountPos); } } float gunAngle = shipAngle + myRelGunAngle; myGun.update(ic, game, gunAngle, creator, shouldShoot, faction); }
From source file:org.destinationsol.game.input.AiPilot.java
License:Apache License
@Override public void updateFar(SolGame 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(); EngineItem engine = farShip.getEngine(); float ts = game.getTimeStep(); if (dest == null || engine == null) { if (myPlanetBind == null) { if (myBindAwait > 0) { myBindAwait -= ts;/*w w w. j a v a 2s . c o m*/ } 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 = SolMath.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 = SolMath.approach(spd.len(), desiredSpdLen, spdLenDiff); if (toDestLen < spdLen) spdLen = toDestLen; SolMath.fromAl(spd, desiredAngle, spdLen); } angle = SolMath.approachAngle(angle, desiredAngle, engine.getMaxRotSpd() * ts); } farShip.setSpd(spd); farShip.setAngle(angle); Vector2 newPos = SolMath.getVec(spd); newPos.scl(ts); newPos.add(shipPos); farShip.setPos(newPos); SolMath.free(newPos); }