List of usage examples for com.badlogic.gdx.math Vector2 add
@Override
public Vector2 add(Vector2 v)
From source file:org.ams.prettypaint.TextureAligner.java
License:Open Source License
/** * Align the given textures so that they can seamlessly overlap. * * @param texturePolygons the textures to align. * @param textureAngleRad the angle to rotate the textures before aligning them. *//* w w w . j av a 2 s. c o m*/ public void alignTextures(Array<TexturePolygon> texturePolygons, float textureAngleRad) { if (texturePolygons.size == 0) return; Vector2 origin = getOrigin(texturePolygons, ORIGIN_CENTER); origin.add(extraTranslation); for (TexturePolygon texturePolygon : texturePolygons) { texturePolygon.setTextureAngle(textureAngleRad - texturePolygon.getAngle()); texturePolygon.alignTexture(origin); } }
From source file:org.ams.testapps.paintandphysics.cardhouse.TurnCircle.java
License:Open Source License
/** Create vertices forming the outline of a circle. */ private Array<Vector2> makeCircle(Vector2 center, float radius) { Array<Vector2> vertices = new Array<Vector2>(); int n = 100;/*from w w w . ja v a 2s. c o m*/ for (int i = 0; i < n; i++) { Vector2 vertex = new Vector2(radius, 0); vertex.rotateRad(i * MathUtils.PI2 / n); vertex.add(center); vertices.add(vertex); } return vertices; }
From source file:org.destinationsol.CommonDrawer.java
License:Apache License
public void drawCircle(TextureRegion tex, Vector2 center, float radius, Color col, float width, float vh) { float relRad = radius / vh; int pointCount = (int) (160 * relRad); Vector2 pos = SolMath.getVec(); if (pointCount < 8) pointCount = 8;/*from w w w .j av a2s.c o m*/ float lineLen = radius * SolMath.PI * 2 / pointCount; float angleStep = 360f / pointCount; float angleStepH = angleStep / 2; for (int i = 0; i < pointCount; i++) { float angle = angleStep * i; SolMath.fromAl(pos, angle, radius); pos.add(center); draw(tex, width, lineLen, (float) 0, (float) 0, pos.x, pos.y, angle + angleStepH, col); } SolMath.free(pos); }
From source file:org.destinationsol.game.asteroid.Asteroid.java
License:Apache License
private void maybeSplit(SolGame game) { if (MIN_SPLIT_SZ > mySize) return;/*ww w.jav a 2s. c o m*/ float sclSum = 0; while (sclSum < .7f * mySize * mySize) { float spdAngle = SolMath.rnd(180); Vector2 spd = new Vector2(); SolMath.fromAl(spd, spdAngle, SolMath.rnd(0, .5f) * MAX_SPLIT_SPD); spd.add(mySpd); Vector2 newPos = new Vector2(); SolMath.fromAl(newPos, spdAngle, SolMath.rnd(0, mySize / 2)); newPos.add(myPos); float sz = mySize * SolMath.rnd(.25f, .5f); Asteroid a = game.getAsteroidBuilder().buildNew(game, newPos, spd, sz, myRemoveController); game.getObjMan().addObjDelayed(a); sclSum += a.mySize * a.mySize; } float thrMoney = mySize * 40f * SolMath.rnd(.3f, 1); List<MoneyItem> moneyItems = game.getItemMan().moneyToItems(thrMoney); for (MoneyItem mi : moneyItems) { throwLoot(game, mi); } }
From source file:org.destinationsol.game.asteroid.Asteroid.java
License:Apache License
private void throwLoot(SolGame game, SolItem item) { float spdAngle = SolMath.rnd(180); Vector2 lootSpd = new Vector2(); SolMath.fromAl(lootSpd, spdAngle, SolMath.rnd(0, Loot.MAX_SPD)); lootSpd.add(mySpd); Vector2 pos = new Vector2(); SolMath.fromAl(pos, spdAngle, SolMath.rnd(0, mySize / 2)); pos.add(myPos);//from w ww . j a v a 2 s . c o m Loot l = game.getLootBuilder().build(game, pos, item, lootSpd, Loot.MAX_LIFE, SolMath.rnd(Loot.MAX_ROT_SPD), null); game.getObjMan().addObjDelayed(l); }
From source file:org.destinationsol.game.BeaconHandler.java
License:Apache License
private void maybeUpdatePlanetPos(SolGame game) { Vector2 beaconPos = getPos0(); if (myPlanetBind == null) { myPlanetBind = PlanetBind.tryBind(game, beaconPos, 0); return;/*from ww w .ja v a 2 s .c om*/ } Vector2 vec = SolMath.getVec(); myPlanetBind.setDiff(vec, beaconPos, false); beaconPos.add(vec); SolMath.free(vec); myPlanetBind.getPlanet().calcSpdAtPos(mySpd, beaconPos); }
From source file:org.destinationsol.game.GalaxyFiller.java
License:Apache License
private Vector2 getPosForStation(SolSystem sys, boolean mainStation, ConsumedAngles angles) { Planet p;/*from w ww . ja va2 s .c o m*/ ArrayList<Planet> planets = sys.getPlanets(); float angleToSun; if (mainStation) { p = planets.get(planets.size() - 2); angleToSun = p.getAngleToSys() + 20 * SolMath.toInt(p.getToSysRotSpd() > 0); } else { int pIdx = SolMath.intRnd(planets.size() - 1); p = planets.get(pIdx); angleToSun = 0; for (int i = 0; i < 10; i++) { angleToSun = SolMath.rnd(180); if (!angles.isConsumed(angleToSun, STATION_CONSUME_SECTOR)) break; } } angles.add(angleToSun, STATION_CONSUME_SECTOR); float stationDist = p.getDist() + p.getFullHeight() + Const.PLANET_GAP; Vector2 stationPos = new Vector2(); SolMath.fromAl(stationPos, angleToSun, stationDist); stationPos.add(p.getSys().getPos()); return stationPos; }
From source file:org.destinationsol.game.GalaxyFiller.java
License:Apache License
private Vector2 getEmptySpace(SolGame game, SolSystem s) { Vector2 res = new Vector2(); Vector2 sPos = s.getPos();/* w ww .ja v a 2s.com*/ float sRadius = s.getConfig().hard ? s.getRadius() : s.getInnerRad(); for (int i = 0; i < 100; i++) { SolMath.fromAl(res, SolMath.rnd(180), SolMath.rnd(sRadius)); res.add(sPos); if (game.isPlaceEmpty(res, true)) return res; } throw new AssertionError("could not generate ship position"); }
From source file:org.destinationsol.game.GalaxyFiller.java
License:Apache License
public Vector2 getPlayerSpawnPos(SolGame game) { Vector2 pos = new Vector2(Const.SUN_RADIUS * 2, 0); if ("planet".equals(DebugOptions.SPAWN_PLACE)) { Planet p = game.getPlanetMan().getPlanets().get(0); pos.set(p.getPos());/*w w w . j av a2 s. com*/ pos.x += p.getFullHeight(); } else if (DebugOptions.SPAWN_PLACE.isEmpty() && myMainStationPos != null) { SolMath.fromAl(pos, 90, myMainStationHc.getSize() / 2); pos.add(myMainStationPos); } else if ("maze".equals(DebugOptions.SPAWN_PLACE)) { Maze m = game.getPlanetMan().getMazes().get(0); pos.set(m.getPos()); pos.x += m.getRadius(); } else if ("trader".equals(DebugOptions.SPAWN_PLACE)) { HullConfig cfg = game.getHullConfigs().getConfig("bus"); for (FarObjData fod : game.getObjMan().getFarObjs()) { FarObj fo = fod.fo; if (!(fo instanceof FarShip)) continue; if (((FarShip) fo).getHullConfig() != cfg) continue; pos.set(fo.getPos()); pos.add(cfg.getApproxRadius() * 2, 0); break; } } return pos; }
From source file:org.destinationsol.game.gun.SolGun.java
License:Apache License
public void update(ItemContainer ic, SolGame game, float gunAngle, SolObject creator, boolean shouldShoot, Faction faction) {//from w ww.ja va 2s .com float baseAngle = creator.getAngle(); Vector2 basePos = creator.getPosition(); float gunRelAngle = gunAngle - baseAngle; mySprite.relAngle = gunRelAngle; Vector2 muzzleRelPos = SolMath.fromAl(gunRelAngle, myItem.config.gunLength); muzzleRelPos.add(myRelPos); if (myLightSrc != null) myLightSrc.setRelPos(muzzleRelPos); Vector2 muzzlePos = SolMath.toWorld(muzzleRelPos, baseAngle, basePos); SolMath.free(muzzleRelPos); float ts = game.getTimeStep(); if (myItem.ammo <= 0 && myItem.reloadAwait <= 0) { if (myItem.config.clipConf.infinite || ic != null && ic.tryConsumeItem(myItem.config.clipConf.example)) { myItem.reloadAwait = myItem.config.reloadTime + .0001f; game.getSoundMan().play(game, myItem.config.reloadSound, null, creator); } } else if (myItem.reloadAwait > 0) { myItem.reloadAwait -= ts; if (myItem.reloadAwait <= 0) { myItem.ammo = myItem.config.clipConf.size; } } if (myCoolDown > 0) myCoolDown -= ts; boolean shot = shouldShoot && myCoolDown <= 0 && myItem.ammo > 0; if (shot) { Vector2 gunSpd = creator.getSpd(); shoot(gunSpd, game, gunAngle, muzzlePos, faction, creator); } else { myCurrAngleVar = SolMath.approach(myCurrAngleVar, myItem.config.minAngleVar, myItem.config.angleVarDamp * ts); } if (myLightSrc != null) myLightSrc.update(shot, baseAngle, game); SolMath.free(muzzlePos); }