List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:ch.coldpixel.mario.Sprites.Mario.java
public void jump() { if (currentState != State.JUMPING) { b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true); currentState = State.JUMPING; }//from www. j a v a 2s .c o m }
From source file:com.a2client.util.Vec2i.java
License:Open Source License
public Vector2 getVector2() { return new Vector2(x, y); }
From source file:com.agateau.pixelwheels.GameWorld.java
License:Open Source License
public GameWorld(PwGame game, GameInfo gameInfo, PerformanceCounters performanceCounters) { mGame = game;//from w w w . ja v a2 s . c o m mBox2DWorld = new World(new Vector2(0, 0), true); mBox2DWorld.setContactListener(this); mTrack = gameInfo.getTrack(); mTrack.init(); mCountDown = new CountDown(this, game.getAudioManager(), game.getAssets().soundAtlas); mBox2DPerformanceCounter = performanceCounters.add("- box2d"); mGameObjectPerformanceCounter = performanceCounters.add("- g.o"); setupRacers(gameInfo.getEntrants()); setupRoadBorders(); setupBonusSpots(); setupBonusPools(); }
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
public Array<Vector2> findStartTilePositions() { Array<Vector2> lst = new Array<Vector2>(); TiledMapTileLayer groundLayer = mBackgroundLayers.get(0); for (int ty = 0; ty < groundLayer.getHeight(); ++ty) { for (int tx = 0; tx < groundLayer.getWidth(); ++tx) { TiledMapTileLayer.Cell cell = groundLayer.getCell(tx, ty); if (cell == null) { continue; }/*w w w.j a v a 2 s. c om*/ int tileId = cell.getTile().getId(); if (tileId == mStartTileId) { Vector2 pos = new Vector2(tx * mTileWidth + mTileWidth / 2, ty * mTileHeight); lst.add(pos); } } } return lst; }
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
public Array<Vector2> findBonusSpotPositions() { final float U = Constants.UNIT_FOR_PIXEL; MapLayer layer = mMap.getLayers().get("BonusSpots"); Assert.check(layer != null, "No BonusSpots layer"); Array<Vector2> lst = new Array<Vector2>(); for (MapObject object : layer.getObjects()) { if (!(object instanceof EllipseMapObject)) { throw new RuntimeException( "BonusSpots layer should contains only ellipses. " + object + " is not an ellipse."); }//w w w . ja va2s . c o m Ellipse ellipse = ((EllipseMapObject) object).getEllipse(); Vector2 pos = new Vector2(ellipse.x * U, ellipse.y * U); lst.add(pos); } return lst; }
From source file:com.agateau.pixelwheels.map.WaypointStore.java
License:Open Source License
public void read(MapLayer layer, LapPositionTable lapPositionTable) { final float U = Constants.UNIT_FOR_PIXEL; for (MapObject object : layer.getObjects()) { Assert.check(object instanceof EllipseMapObject, "Waypoints layer should contains only ellipses. " + object + " is not an ellipse."); Ellipse ellipse = ((EllipseMapObject) object).getEllipse(); final LapPosition pos = lapPositionTable.get((int) ellipse.x, (int) ellipse.y); WaypointInfo info = new WaypointInfo(); info.waypoint = new Vector2(ellipse.x * U, ellipse.y * U); info.lapDistance = pos.getLapDistance(); mWaypointInfos.add(info);//from ww w. j a v a 2 s . c om } mWaypointInfos.sort(); }
From source file:com.agateau.ui.anchor.PositionRule.java
License:Apache License
@Override public void apply() { // Compute reference position Vector2 referencePos = new Vector2(reference.getWidth() * referenceAnchor.hPercent, reference.getHeight() * referenceAnchor.vPercent); Vector2 stagePos = reference.localToStageCoordinates(referencePos); // Apply space stagePos.add(hSpace, vSpace);/* w w w . ja va2 s . c o m*/ // Position target (use target parent because setPosition() works in parent coordinates) Actor targetParent = target.getParent(); if (targetParent == null) { return; } Vector2 targetPos = targetParent.stageToLocalCoordinates(stagePos); // Apply target offset (If right-aligned, hPercent is 100% => -width * scale. // If centered, hPercent is 50% => -width * scale / 2) targetPos.add(-target.getWidth() * target.getScaleX() * targetAnchor.hPercent, -target.getHeight() * target.getScaleY() * targetAnchor.vPercent); //noinspection SuspiciousNameCombination target.setPosition(MathUtils.floor(targetPos.x), MathUtils.floor(targetPos.y)); }
From source file:com.ahsgaming.valleyofbones.ai.AIPlayer.java
License:Apache License
public float calcGoalMatrix(int x, int y, HexMap map, Array<AbstractUnit> units) { float total = 0; for (AbstractUnit unit : units) { if (unit.getData().getType().equals("building")) { int dist = map.getMapDist(unit.getView().getBoardPosition(), new Vector2(x, y)); Float value = 0f;/* w w w . j av a2 s . c om*/ Array<Float> coeff_array = new Array<Float>(); if (unit.getProto().id.equals("tower")) { value = (Float) genome.chromosomes.get(9).genes.get("tower_val"); if (!visibilityMatrix[(int) (unit.getView().getBoardPosition().y * map.getWidth() + unit.getView().getBoardPosition().x)] || unit.getOwner() == null) { // neutral tower coeff_array = (Array<Float>) genome.chromosomes.get(9).genes.get("tower_n_coeff"); } else if (unit.getOwner() == this) { // friendly tower coeff_array = (Array<Float>) genome.chromosomes.get(9).genes.get("tower_f_coeff"); } else { // enemy tower coeff_array = (Array<Float>) genome.chromosomes.get(9).genes.get("tower_e_coeff"); } } else { if (unit.getOwner() == this) { // friendly castle value = threatMatrix[(int) (unit.getView().getBoardPosition().y * map.getWidth() + unit.getView().getBoardPosition().x)]; coeff_array = (Array<Float>) genome.chromosomes.get(9).genes.get("castle_f_coeff"); } else { // enemy castle value = (Float) genome.chromosomes.get(9).genes.get("castle_e_value"); coeff_array = (Array<Float>) genome.chromosomes.get(9).genes.get("castle_e_coeff"); } } total += calc_value(value, dist, coeff_array); } } return total; }
From source file:com.ahsgaming.valleyofbones.ai.AIPlayer.java
License:Apache License
public boolean[] createVisibilityMatrix(HexMap map, Array<AbstractUnit> units) { boolean[] matrix = new boolean[map.getWidth() * map.getHeight()]; for (AbstractUnit unit : units) { if (unit.getData().isBuilding()) continue; int range = unit.getData().getSightRange(); for (int x = (int) Math.max(unit.getView().getBoardPosition().x - range - 1, 0); x < Math .min(unit.getView().getBoardPosition().x + range + 1, map.getWidth()); x++) { for (int y = (int) Math.max(unit.getView().getBoardPosition().y - range - 1, 0); y < Math .min(unit.getView().getBoardPosition().y + range + 1, map.getHeight()); y++) { if (map.getMapDist(new Vector2(x, y), unit.getView().getBoardPosition()) <= range) matrix[y * map.getWidth() + x] = true; }/*ww w.j a va 2 s . c o m*/ } } return matrix; }
From source file:com.ahsgaming.valleyofbones.ai.AIPlayer.java
License:Apache License
public float calcUnitMatrix(int x, int y, HexMap map, Array<AbstractUnit> units, boolean threat) { float total = 0; for (AbstractUnit unit : units) { if (unit.getOwner() == this) { int i = Prototypes.getAll(getRace()).indexOf(Prototypes.getProto(getRace(), unit.getProto().id), true);//from www . ja va 2 s .co m total += calc_value((Float) genome.chromosomes.get(i).genes.get((threat ? "threat" : "value")), // TODO this is a horrible way to look this up map.getMapDist(unit.getView().getBoardPosition(), new Vector2(x, y)), (Array<Float>) genome.chromosomes.get(i).genes .get((threat ? "threat_coeff" : "value_coeff"))); } } return total; }