List of usage examples for com.badlogic.gdx.utils Array removeIndex
public T removeIndex(int index)
From source file:com.agateau.pixelwheels.GameConfig.java
License:Open Source License
private void setupInputHandlers() { Map<String, Array<GameInputHandler>> inputHandlersByIds = GameInputHandlerFactories.getInputHandlersByIds(); for (int idx = 0; idx < Constants.MAX_PLAYERS; ++idx) { mPlayerInputHandlers[idx] = null; String id = mPlayerInputFactoryIds[idx]; if ("".equals(id)) { id = GameInputHandlerFactories.getAvailableFactories().first().getId(); }/* ww w .j av a 2 s. com*/ Array<GameInputHandler> inputHandlers = inputHandlersByIds.get(id); if (inputHandlers == null) { NLog.e("Player %d: no input handlers for id '%s'", idx + 1, id); continue; } if (inputHandlers.size == 0) { NLog.i("Player %d: not enough input handlers for id '%s'", idx + 1, id); continue; } GameInputHandler inputHandler = inputHandlers.removeIndex(0); inputHandler.loadConfig(mPreferences, getInputPrefix(idx)); mPlayerInputHandlers[idx] = inputHandler; } }
From source file:com.ahsgaming.superrummy.GameController.java
License:Apache License
public Array<Card> shuffle() { // two decks! Array<Card> available = new Array<Card>(); Array<Card> shuffled = new Array<Card>(); for (int s = 0; s < 4; s++) { Suits suit = Suits.values()[s];/* ww w . j av a2s . c o m*/ for (int v = Values.ACE.ordinal(); v <= Values.KING.ordinal(); v++) { Values value = Values.values()[v]; available.add(new Card(value, suit)); available.add(new Card(value, suit)); } } available.add(new Card(Values.JOKER, Suits.NONE)); available.add(new Card(Values.JOKER, Suits.NONE)); available.add(new Card(Values.JOKER, Suits.NONE)); available.add(new Card(Values.JOKER, Suits.NONE)); while (available.size > 0) shuffled.add(available.removeIndex((int) (Math.random() * available.size))); return shuffled; }
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);//www . ja va 2 s .com 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.android.ringfly.common.Colliders.java
License:Apache License
/** Removes game objects that are marked as in collision, calling a removal handler for each one that is marked. Note that the * "U extends T" part of this method's signature means, for example, that PlayerShot and RobotShot can both have the same * handler if they are both derived from BaseShot. * /*from w w w .java2 s .c o m*/ * @param <T> the base class of the object. * @param <U> a more specific class of the object. * @param pool the pool to which the object belongs. * @param gos the array of game objects to check. * @param handler the collision handler callback. */ public static <T extends GameObject, U extends T> void removeMarkedCollisions(Pool<U> pool, Array<U> gos, RemovalHandler<T> handler) { // The "U extends T" allows for shotHandler to cope with both PlayerShot and RobotShot, because they both // extend BaseShot. for (int i = gos.size - 1; i >= 0; i--) { U go = gos.get(i); if (go.inCollision) { handler.onRemove(go); gos.removeIndex(i); pool.free(go); } } }
From source file:com.android.ringfly.common.Colliders.java
License:Apache License
/** Removes game objects that are outside of the given rectangular bounds. * @param <T> the object's class.//w ww .ja v a 2s. c o m * @param pool the pool to which the object belongs. * @param gos the array of game objects to check. * @param bounds the rectangular bounds. */ public static <T extends GameObject> void removeOutOfBounds(Pool<T> pool, Array<T> gos, Rectangle bounds) { float minX = bounds.x; float maxX = minX + bounds.width; float minY = bounds.y; float maxY = minY + bounds.height; for (int i = gos.size - 1; i >= 0; i--) { T go = gos.get(i); if (go.x >= maxX || go.x + go.width <= minX || go.y >= maxY || go.y + go.height <= minY) { gos.removeIndex(i); pool.free(go); } } }
From source file:com.bladecoder.engineeditor.ui.LayerList.java
License:Apache License
private void up() { int pos = list.getSelectedIndex(); if (pos == -1 || pos == 0) return;/* www.j ava2 s .co m*/ Array<SceneLayer> items = list.getItems(); SceneLayer e = items.get(pos); SceneLayer e2 = items.get(pos - 1); parent.getLayers().set(pos, e2); parent.getLayers().set(pos - 1, e); items.removeIndex(pos); items.insert(pos - 1, e); list.setSelectedIndex(pos - 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.bladecoder.engineeditor.ui.LayerList.java
License:Apache License
private void down() { int pos = list.getSelectedIndex(); Array<SceneLayer> items = list.getItems(); if (pos == -1 || pos == items.size - 1) return;// ww w .ja v a2s.com SceneLayer e = items.get(pos); SceneLayer e2 = pos + 1 < items.size ? items.get(pos + 1) : null; parent.getLayers().set(pos, e2); parent.getLayers().set(pos + 1, e); items.removeIndex(pos); items.insert(pos + 1, e); list.setSelectedIndex(pos + 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.esotericsoftware.spine.utils.Triangulator.java
License:Open Source License
public Array<FloatArray> decompose(FloatArray verticesArray, ShortArray triangles) { float[] vertices = verticesArray.items; Array<FloatArray> convexPolygons = this.convexPolygons; polygonPool.freeAll(convexPolygons); convexPolygons.clear();//from w ww . ja v a 2 s . c o m Array<ShortArray> convexPolygonsIndices = this.convexPolygonsIndices; polygonIndicesPool.freeAll(convexPolygonsIndices); convexPolygonsIndices.clear(); ShortArray polygonIndices = polygonIndicesPool.obtain(); polygonIndices.clear(); FloatArray polygon = polygonPool.obtain(); polygon.clear(); // Merge subsequent triangles if they form a triangle fan. int fanBaseIndex = -1, lastWinding = 0; short[] trianglesItems = triangles.items; for (int i = 0, n = triangles.size; i < n; i += 3) { int t1 = trianglesItems[i] << 1, t2 = trianglesItems[i + 1] << 1, t3 = trianglesItems[i + 2] << 1; float x1 = vertices[t1], y1 = vertices[t1 + 1]; float x2 = vertices[t2], y2 = vertices[t2 + 1]; float x3 = vertices[t3], y3 = vertices[t3 + 1]; // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). boolean merged = false; if (fanBaseIndex == t1) { int o = polygon.size - 4; float[] p = polygon.items; int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); if (winding1 == lastWinding && winding2 == lastWinding) { polygon.add(x3); polygon.add(y3); polygonIndices.add(t3); merged = true; } } // Otherwise make this triangle the new base. if (!merged) { if (polygon.size > 0) { convexPolygons.add(polygon); convexPolygonsIndices.add(polygonIndices); } else { polygonPool.free(polygon); polygonIndicesPool.free(polygonIndices); } polygon = polygonPool.obtain(); polygon.clear(); polygon.add(x1); polygon.add(y1); polygon.add(x2); polygon.add(y2); polygon.add(x3); polygon.add(y3); polygonIndices = polygonIndicesPool.obtain(); polygonIndices.clear(); polygonIndices.add(t1); polygonIndices.add(t2); polygonIndices.add(t3); lastWinding = winding(x1, y1, x2, y2, x3, y3); fanBaseIndex = t1; } } if (polygon.size > 0) { convexPolygons.add(polygon); convexPolygonsIndices.add(polygonIndices); } // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. for (int i = 0, n = convexPolygons.size; i < n; i++) { polygonIndices = convexPolygonsIndices.get(i); if (polygonIndices.size == 0) continue; int firstIndex = polygonIndices.get(0); int lastIndex = polygonIndices.get(polygonIndices.size - 1); polygon = convexPolygons.get(i); int o = polygon.size - 4; float[] p = polygon.items; float prevPrevX = p[o], prevPrevY = p[o + 1]; float prevX = p[o + 2], prevY = p[o + 3]; float firstX = p[0], firstY = p[1]; float secondX = p[2], secondY = p[3]; int winding = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); for (int ii = 0; ii < n; ii++) { if (ii == i) continue; ShortArray otherIndices = convexPolygonsIndices.get(ii); if (otherIndices.size != 3) continue; int otherFirstIndex = otherIndices.get(0); int otherSecondIndex = otherIndices.get(1); int otherLastIndex = otherIndices.get(2); FloatArray otherPoly = convexPolygons.get(ii); float x3 = otherPoly.get(otherPoly.size - 2), y3 = otherPoly.get(otherPoly.size - 1); if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); if (winding1 == winding && winding2 == winding) { otherPoly.clear(); otherIndices.clear(); polygon.add(x3); polygon.add(y3); polygonIndices.add(otherLastIndex); prevPrevX = prevX; prevPrevY = prevY; prevX = x3; prevY = y3; ii = 0; } } } // Remove empty polygons that resulted from the merge step above. for (int i = convexPolygons.size - 1; i >= 0; i--) { polygon = convexPolygons.get(i); if (polygon.size == 0) { convexPolygons.removeIndex(i); polygonPool.free(polygon); polygonIndices = convexPolygonsIndices.removeIndex(i); polygonIndicesPool.free(polygonIndices); } } return convexPolygons; }
From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * creates {@link com.badlogic.gdx.physics.box2d.Fixture Fixtures} from a {@link com.badlogic.gdx.maps.MapObject} * * @param mapObject the {@link com.badlogic.gdx.maps.MapObject} to parse * @return an array of parsed {@link com.badlogic.gdx.physics.box2d.Fixture Fixtures} */// w ww.j a v a 2 s. co m public Fixture[] createFixtures(MapObject mapObject) { Polygon polygon; if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon())) return new Fixture[] { createFixture(mapObject) }; Polygon[] convexPolygons; if (triangulate) { if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better) Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices())); Vector2 first = vertices.removeIndex(0); vertices.reverse(); vertices.insert(0, first); polygon.setVertices(toFloatArray(vertices.items)); } convexPolygons = toPolygonArray(toVector2Array( new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3); } else { Array<Array<Vector2>> convexPolys = BayazitDecomposer .convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices()))); convexPolygons = new Polygon[convexPolys.size]; for (int i = 0; i < convexPolygons.length; i++) convexPolygons[i] = new Polygon( toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class))); } // create the fixtures using the convex polygons Fixture[] fixtures = new Fixture[convexPolygons.length]; for (int i = 0; i < fixtures.length; i++) { PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]); convexObject.setColor(mapObject.getColor()); convexObject.setName(mapObject.getName()); convexObject.setOpacity(mapObject.getOpacity()); convexObject.setVisible(mapObject.isVisible()); convexObject.getProperties().putAll(mapObject.getProperties()); fixtures[i] = createFixture(convexObject); } return fixtures; }
From source file:com.kotcrab.vis.editor.module.physicseditor.PRigidBodiesScreen.java
License:Apache License
public void removeSelectedPoints() { if (!isRemoveEnabled()) return;/*from ww w . ja v a 2 s .co m*/ Array<ShapeModel> shapes = selectedModel.getShapes(); for (int i = shapes.size - 1; i >= 0; i--) { ShapeModel shape = selectedModel.getShapes().get(i); switch (shape.getType()) { case POLYGON: for (Vector2 p : selectedPoints) { if (shape.getVertices().contains(p, true)) shape.getVertices().removeValue(p, true); } if (shape.getVertices().size == 0) shapes.removeIndex(i); break; case CIRCLE: for (Vector2 p : selectedPoints) { if (shape.getVertices().contains(p, true)) { shapes.removeIndex(i); break; } } break; } } selectedPoints.clear(); selectedModel.computePhysics(settings.polygonizer); }