List of usage examples for com.badlogic.gdx.math Vector2 Zero
Vector2 Zero
To view the source code for com.badlogic.gdx.math Vector2 Zero.
Click Source Link
From source file:org.destinationsol.game.planet.PlanetManager.java
License:Apache License
private boolean recoverObj(SolObject obj, float toNp, float npMinH) { if (npMinH < toNp) return false; if (!(obj instanceof SolShip)) return false; SolShip ship = (SolShip) obj;//from w w w .j a v a 2s . c o m Hull hull = ship.getHull(); if (hull.config.getType() == HullConfig.Type.STATION) return false; float fh = myNearestPlanet.getFullHeight(); Vector2 npPos = myNearestPlanet.getPos(); Vector2 toShip = SolMath.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); SolMath.free(toShip); return true; }
From source file:org.destinationsol.game.ship.EmWave.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 instanceof SolShip) || o == owner) continue; SolShip oShip = (SolShip) o;//from ww w . j a va 2 s . c o m if (!game.getFactionMan().areEnemies(oShip, owner)) continue; Vector2 oPos = o.getPosition(); float dst = oPos.dst(ownerPos); float perc = KnockBack.getPerc(dst, MAX_RADIUS); if (perc <= 0) continue; float duration = perc * myConfig.duration; oShip.disableControls(duration, game); } 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.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);//from w w w. j a v a2s. c om o.receiveForce(toO, game, false); SolMath.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:org.destinationsol.game.ship.Teleport.java
License:Apache License
public void maybeTeleport(SolGame game, SolShip owner) { if (!myShouldTeleport) return;/*from w ww . j a v a 2s . c o m*/ TextureAtlas.AtlasRegion tex = game.getTexMan().getTex(TEX_PATH, null); float blipSz = owner.getHull().config.getApproxRadius() * 3; game.getPartMan().blip(game, owner.getPosition(), SolMath.rnd(180), blipSz, 1, Vector2.Zero, tex); game.getPartMan().blip(game, myNewPos, SolMath.rnd(180), blipSz, 1, Vector2.Zero, tex); float newAngle = owner.getAngle() + myAngle; Vector2 newSpd = SolMath.getVec(owner.getSpd()); SolMath.rotate(newSpd, myAngle); Body body = owner.getHull().getBody(); body.setTransform(myNewPos, newAngle * SolMath.degRad); body.setLinearVelocity(newSpd); SolMath.free(newSpd); }
From source file:org.destinationsol.game.ship.UnShield.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 instanceof SolShip) || o == owner) continue; SolShip oShip = (SolShip) o;/*from w ww . ja v a 2 s.c o m*/ Shield shield = oShip.getShield(); if (shield == null) continue; float shieldLife = shield.getLife(); if (shieldLife <= 0) continue; if (!game.getFactionMan().areEnemies(oShip, owner)) continue; Vector2 oPos = o.getPosition(); float dst = oPos.dst(ownerPos); float perc = KnockBack.getPerc(dst, MAX_RADIUS); if (perc <= 0) continue; float amount = perc * myConfig.amount; if (shieldLife < amount) amount = shieldLife; oShip.receiveDmg(amount, game, ownerPos, DmgType.ENERGY); } 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.StarPort.java
License:Apache License
private static void blip(SolGame game, SolShip ship) { TextureAtlas.AtlasRegion tex = game.getTexMan().getTex(Teleport.TEX_PATH, null); float blipSz = ship.getHull().config.getApproxRadius() * 10; game.getPartMan().blip(game, ship.getPosition(), SolMath.rnd(180), blipSz, 1, Vector2.Zero, tex); }
From source file:org.matheusdev.util.TmxObjectsLoader.java
License:Open Source License
public static void main(String... args) throws IOException { GdxNativesLoader.load();/*from w w w . j a v a 2s .c om*/ Physics physics = new Physics(Vector2.Zero, true); File mapfile = new File("data/maps/newmap/map005.tmx"); Element mapXML = new XmlReader().parse(new FileInputStream(mapfile)); System.out.println(mapXML); new TmxObjectsLoader(mapXML).loadToPhysics(physics, 32, 32, 50, 50); }
From source file:org.saltosion.pixelprophecy.states.GameState.java
License:Open Source License
@Override public void enter() { // Initialize Box2D Box2D.init();// w ww . j a va2s . com engine = new Engine(); world = new World(Vector2.Zero, true); // Create World object gameWorld = new GameWorld(mapLoader, world, engine); // Initialize systems engine.addSystem(ps = new PhysicsSystem(world)); engine.addSystem(rs = new RenderingSystem(world)); engine.addSystem(new MovementSystem()); //Initialize world gameWorld.setRayHandler(rs.getRayHandler()); // Set map setMap(Names.TEST, "playerspawn"); // Set player player = gameWorld.getPlayer(); // Make camera follow player rs.setFollowedEntity(player); // Initialize input multiplexer.addProcessor(inputAdapter = new GameInputAdapter(this)); InputManager.setKey(Input.Keys.W, new MoveInputAction(new Vector2(0, 1), player)); InputManager.setKey(Input.Keys.A, new MoveInputAction(new Vector2(-1, 0), player)); InputManager.setKey(Input.Keys.S, new MoveInputAction(new Vector2(0, -1), player)); InputManager.setKey(Input.Keys.D, new MoveInputAction(new Vector2(1, 0), player)); InputManager.setKey(Input.Keys.I, new InventoryToggleAction(this)); fpsClock = new TextNode("fps-clock", "FPS: Calculating.."); fpsClock.setLocalTranslation(new Vector2(0, 1)); fpsClock.setAlignment(new Vector2(-1, 1)); fpsClock.setScale(10); guiManager.getRootNode().attach(fpsClock); inventorybg = new ImageNode("inventory-bg", SpriteLoader.createSprite(Names.INVENTORY_BG_SPRITE)); inventorybg.setLocalTranslation(new Vector2(1, 1)); inventorybg.setAlignment(new Vector2(1, 1)); inventorybg.setScale(13); guiManager.getRootNode().attach(inventorybg); inventoryfadebg = new ImageNode("inventory-fade-bg", SpriteLoader.createSprite(Names.INVENTORY_FADE_BG)); inventoryfadebg.setLocalTranslation(new Vector2(0, 0)); inventoryfadebg.setScale(13); inventoryfadebg.setAlignment(new Vector2(0, .7f)); inventorybg.attach(inventoryfadebg); inventorybg.setVisible(false); }
From source file:rosthouse.rosty.loader.MapLoader.java
private void createRectangle(RectangleMapObject rectangleObject, PhysicsSystem physicsSystem, Entity mapObjectEntity, boolean isSensor) { Rectangle rectangle = rectangleObject.getRectangle(); RectangleComponent rectComponent = new RectangleComponent(rectangle); PolygonShape polygonShape = new PolygonShape(); polygonShape.setAsBox(rectangle.width * 0.5f, rectangle.height * 0.5f); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = 0;/*from www .j av a 2 s . com*/ fixtureDef.friction = 1; fixtureDef.restitution = 0.2f; PhysicsComponent<PolygonShape> cmpPhys; if (isSensor) { cmpPhys = physicsSystem.createSensorComponent(BodyDef.BodyType.StaticBody, polygonShape, rectangle.getCenter(Vector2.Zero), fixtureDef); } else { cmpPhys = physicsSystem.createPhysicsComponent(BodyDef.BodyType.StaticBody, polygonShape, rectangle.getCenter(Vector2.Zero), fixtureDef); } mapObjectEntity.add(rectComponent); mapObjectEntity.add(cmpPhys); cmpPhys.fixture.setUserData(mapObjectEntity.getId()); }
From source file:vault.clockwork.scene.Actor.java
License:Open Source License
/** * Get the position of the actor. * @return Position vector. */ public Vector2 getPosition() { return Vector2.Zero; }