List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.ahsgaming.valleyofbones.GameController.java
License:Apache License
private void loadMapObjects() { Array<Player> playersToSpawn = new Array<Player>(); switch (spawnType) { case SPAWN_NORMAL: playersToSpawn.addAll(players);//from ww w. j av a 2 s.co m break; case SPAWN_INVERTED: for (int i = players.size - 1; i >= 0; i--) { playersToSpawn.add(players.get(i)); } break; case SPAWN_RANDOM: Array<Player> p = new Array<Player>(players); while (p.size > 0) { playersToSpawn.add(p.removeIndex((int) Math.floor(Math.random() * p.size))); } break; } for (MapData.MapObject spawn : map.getPlayerSpawns()) { AbstractUnit unit; if (spawn.player >= 0 && spawn.player < players.size) { unit = Unit.createUnit(getNextObjectId(), "castle-base", playersToSpawn.get(spawn.player)); playersToSpawn.get(spawn.player).setBaseUnit(unit); } else { unit = Unit.createUnit(getNextObjectId(), "castle-base", null); Gdx.app.log(VOBGame.LOG, "Map Error: player spawn index out of range"); } Vector2 pos = map.boardToMapCoords(spawn.x, spawn.y); unit.getView().setPosition(pos.x, pos.y); unit.getView().setBoardPosition(spawn.x, spawn.y); unitManager.addUnit(unit); if (spawn.player >= 0 && spawn.player < players.size) { addSpawnPoint(playersToSpawn.get(spawn.player).getPlayerId(), new Vector2(unit.getView().getX() + unit.getView().getWidth() * 0.5f, unit.getView().getY() + unit.getView().getHeight() * 0.5f)); } } for (MapData.MapObject obj : map.getControlPoints()) { AbstractUnit unit; unit = Unit.createUnit(getNextObjectId(), obj.proto, obj.player == -1 ? null : players.get(obj.player)); Vector2 pos = map.boardToMapCoords(obj.x, obj.y); unit.getView().setPosition(pos.x, pos.y); unit.getView().setBoardPosition(new Vector2(obj.x, obj.y)); unitManager.addUnit(unit); } if (VOBGame.DEBUG_ATTACK) { AbstractUnit unit = Unit.createUnit(getNextObjectId(), "marine-base", players.get(0)); unit.getView().setBoardPosition(9, 0); unit.getView().setPosition(getMap().boardToMapCoords(9, 0)); unitManager.addUnit(unit); unit = Unit.createUnit(getNextObjectId(), "marine-base", players.get(1)); unit.getView().setBoardPosition(10, 0); unit.getView().setPosition(getMap().boardToMapCoords(10, 0)); unitManager.addUnit(unit); } }
From source file:com.ahsgaming.valleyofbones.GameController.java
License:Apache License
public AbstractUnit getUnitAtBoardPos(int x, int y) { return unitManager.getUnit(new Vector2(x, y)); }
From source file:com.ahsgaming.valleyofbones.GameController.java
License:Apache License
public boolean isBoardPosEmpty(int x, int y) { if (!map.getMapData().isBoardPositionTraversible(x, y)) return false; return (unitManager.getUnit(new Vector2(x, y)) == null); }
From source file:com.ahsgaming.valleyofbones.map.HexMap.java
License:Apache License
public void highlightArea(MapView view, Vector2 center, int radius) { Array<AbstractUnit> units = gameController.getUnits(); boolean[] notavailable = new boolean[view.hexStatus.length]; for (AbstractUnit u : units) { if (!u.getView().getBoardPosition().equals(center)) notavailable[(int) (u.getView().getBoardPosition().y * mapData.bounds.x + u.getView().getBoardPosition().x)] = true; }/*from w w w . j a va 2s . com*/ int[] start = { (int) (center.y * mapData.bounds.x + center.x) }; int[] radii = { radius }; boolean[] available = getAvailablePositions(start, radii, notavailable, true); for (int i = 0; i < view.hexStatus.length; i++) { if (available[i] && view.hexStatus[i] != MapView.FOG) { if (notavailable[i] || i == start[0]) { view.hexDimmed[i] = true; view.hexStatus[i] = MapView.DIMMED; } else { view.hexHighlight[i] = true; view.hexStatus[i] = MapView.HIGHLIGHT; } } else if (view.hexStatus[i] != MapView.FOG) { if (getMapDist(center, new Vector2((int) (i % mapData.bounds.x), (int) (i / mapData.bounds.x))) <= radius) { view.hexDimmed[i] = true; view.hexStatus[i] = MapView.DIMMED; } } } }
From source file:com.ahsgaming.valleyofbones.map.HexMap.java
License:Apache License
public static Vector2 boardToMapCoords(MapData data, int bx, int by) { return new Vector2(bx * data.tileSize.x + (by % 2 == 1 ? data.tileSize.x * 0.5f : 0), by * data.tileSize.y * 0.75f); }
From source file:com.ahsgaming.valleyofbones.map.HexMap.java
License:Apache License
public static Vector2[] getAdjacent(int x, int y) { Vector2[] adjacent = new Vector2[6]; adjacent[0] = new Vector2(x + 1, y); adjacent[1] = new Vector2(x - 1, y); adjacent[2] = new Vector2(x + (y % 2 == 0 ? 0 : 1), y - 1); adjacent[3] = new Vector2(x + (y % 2 == 0 ? 0 : 1), y + 1); adjacent[4] = new Vector2(x + (y % 2 == 0 ? -1 : 0), y - 1); adjacent[5] = new Vector2(x + (y % 2 == 0 ? -1 : 0), y + 1); return adjacent; }
From source file:com.ahsgaming.valleyofbones.screens.LevelScreen.java
License:Apache License
private void drawUnitBoxes() { if (selected != null) { unitBoxRenderer.draw(mapCamera.combined, selected, gController.getMap().boardToMapCoords(selected.getView().getBoardPosition().x, selected.getView().getBoardPosition().y), new Vector2((posCamera.x - mapCamera.viewportWidth * 0.5f), (posCamera.y - mapCamera.viewportHeight * 0.5f)), new Vector2(gController.getMap().getTileWidth(), gController.getMap().getTileHeight())); }// w w w .j a va 2 s. c o m }
From source file:com.ahsgaming.valleyofbones.screens.LevelScreen.java
License:Apache License
public void zoom(float amount) { if (menuMode) return;/*from w w w . j a v a 2 s .c o m*/ mapScale.set(mapScale.x * amount, mapScale.y * amount); mapCamera.setToOrtho(false, stage.getCamera().viewportWidth * mapScale.x, stage.getCamera().viewportHeight * mapScale.y); Vector2 map = screenToMapCoords(stage.getWidth() * 0.5f, stage.getHeight() * 0.5f); Vector2 screen = mapToScreenCoords(map.x, map.y); Gdx.app.log(LOG, "" + new Vector2(stage.getWidth() * 0.5f, stage.getHeight() * 0.5f)); Gdx.app.log(LOG, "" + map); Gdx.app.log(LOG, "" + screen); }
From source file:com.ahsgaming.valleyofbones.screens.LevelScreen.java
License:Apache License
public Vector2 screenToMapCoords(float x, float y) { x *= mapScale.x;//ww w . j av a 2s . co m y *= mapScale.y; return new Vector2(x + (posCamera.x - mapCamera.viewportWidth * 0.5f), y + (posCamera.y - mapCamera.viewportHeight * 0.5f)); }
From source file:com.ahsgaming.valleyofbones.screens.LevelScreen.java
License:Apache License
public Vector2 mapToScreenCoords(float x, float y) { x -= (posCamera.x - mapCamera.viewportWidth * 0.5f); x /= mapScale.x;/*from w w w . j a v a 2 s . c o m*/ y -= (posCamera.y - mapCamera.viewportHeight * 0.5f); y /= mapScale.y; return new Vector2(x, y); }