List of usage examples for com.badlogic.gdx.utils ArrayMap ArrayMap
public ArrayMap()
From source file:com.algodal.gdxscreen.GdxGame.java
License:Apache License
public GdxGame() { screenMap = new ArrayMap<>(); transitionMap = new ArrayMap<>(); assetMap = new ArrayMap<>(); assetManager = new AssetManager(); defaultScreen = new GdxScreen().setGame(this); screenListener = new ScreenListener(); debug = new GdxDebug().setOn(true); //debugging is on by default //I like this kind of coding where I embed debugging within my main //code. I find it useful because it allows me to avoid using large //amount of nested if statements. In this code I do not have to add //comment to the debug code because the tag strings are descriptive. library = new GdxLibrary(); clearColor = new Color(Color.RED); pauseStatus = false; //initially the game is not paused. }
From source file:com.algodal.gdxscreen.utils.GdxLibrary.java
License:Apache License
public GdxLibrary() { contentMap = new ArrayMap<>(); debug = new GdxDebug().setOn(true); }
From source file:com.mygdx.game.objects.Ragdoll.java
License:Apache License
/** * @param empties Blender empties containing rigid body dimension data * @param armatureNodeId The name of the root skeleton/armature node */// w w w. j a v a 2 s . c om private void createRagdoll(Array<BlenderEmpty> empties, String armatureNodeId) { Node armature = modelInstance.getNode(armatureNodeId, true, true); // Load mass and shape half extent data from Blender json ArrayMap<String, Vector3> halfExtMap = new ArrayMap<String, Vector3>(); ArrayMap<String, Float> massMap = new ArrayMap<String, Float>(); for (BlenderEmpty empty : empties) { Vector3 halfExtents = new Vector3(empty.scale); halfExtents.x = Math.abs(halfExtents.x); halfExtents.y = Math.abs(halfExtents.y); halfExtents.z = Math.abs(halfExtents.z); halfExtMap.put(empty.name, halfExtents); float partMass = Float.parseFloat(empty.custom_properties.get("mass")); massMap.put(empty.name, super.mass * partMass); } ArrayMap<String, btCollisionShape> shapeMap = new ArrayMap<String, btCollisionShape>(); ArrayMap<String, btRigidBody> bodyMap = new ArrayMap<String, btRigidBody>(); // Create rigid bodies using the previously loaded mass and half extents. // Put them along with the shapes into maps. for (Iterator<ObjectMap.Entry<String, Vector3>> iterator = halfExtMap.iterator(); iterator.hasNext();) { ObjectMap.Entry<String, Vector3> entry = iterator.next(); String partName = entry.key; Vector3 partHalfExt = entry.value; float partMass = massMap.get(partName); btCollisionShape partShape = new btBoxShape(partHalfExt); shapeMap.put(partName, partShape); InvisibleBody phyCmp = new InvisibleBody(partName, partShape, partMass, new Matrix4(), this.belongsToFlag, this.collidesWithFlag, false, true); phyCmp.constructionInfo.dispose(); bodyMap.put(partName, phyCmp.body); this.addPart(phyCmp.body, armature.getChild(partName, true, true)); } // Abdomen is the at the top of the armature hierarchy this.addPart(bodyMap.get("abdomen"), armature, new Vector3(0, halfExtMap.get("abdomen").y * 1.6f, 0)); final Matrix4 localA = new Matrix4(); final Matrix4 localB = new Matrix4(); btHingeConstraint hingeC; btConeTwistConstraint coneC; btFixedConstraint fixedC; String a, b; // TODO: This part could probably be automated somehow... // Set the ragdollConstraints a = "abdomen"; b = "chest"; localA.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); hingeC.setLimit(-PI0_25, PI0_5); a = "chest"; b = "neck"; localA.setFromEulerAnglesRad(0, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(fixedC = new btFixedConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); a = "neck"; b = "head"; localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); coneC.setLimit(PI0_25, PI0_25, PI0_25); a = "abdomen"; b = "left_thigh"; localA.setFromEulerAnglesRad(0, PI, 0).scl(-1, 1, 1).trn(halfExtMap.get(a).x * 0.5f, -halfExtMap.get("abdomen").y, 0); localB.setFromEulerAnglesRad(0, 0, 0).scl(-1, 1, 1).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); coneC.setLimit(PI0_25, PI0_25, PI0_25); coneC.setDamping(10); a = "abdomen"; b = "right_thigh"; localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x * 0.5f, -halfExtMap.get("abdomen").y, 0); localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); coneC.setLimit(PI0_25, PI0_25, PI0_25); coneC.setDamping(10); a = "left_thigh"; b = "left_shin"; localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); hingeC.setLimit(0, PI0_25 * 3); a = "right_thigh"; b = "right_shin"; localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); hingeC.setLimit(0, PI0_25 * 3); // TODO: causes shoulder rotation a = "chest"; b = "left_upper_arm"; localA.setFromEulerAnglesRad(0, PI, 0).trn(halfExtMap.get(a).x + halfExtMap.get(b).x, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(PI0_25, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); coneC.setLimit(PI0_5, PI0_5, 0); coneC.setDamping(10); // TODO: as above a = "chest"; b = "right_upper_arm"; localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x - halfExtMap.get(b).x, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(-PI0_25, 0, 0).trn(0, -halfExtMap.get("right_upper_arm").y, 0); this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); coneC.setLimit(PI0_5, PI0_5, 0); coneC.setDamping(10); a = "left_upper_arm"; b = "left_forearm"; localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); hingeC.setLimit(0, PI0_5); a = "right_upper_arm"; b = "right_forearm"; localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0); localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0); this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB)); hingeC.setLimit(0, PI0_5); }
From source file:com.mygdx.game.pathfinding.NavMeshGraph.java
License:Apache License
/** * Map the isolated edges for each triangle which does not have all three edges connected to other triangles. * * @param connectionMap// ww w . j ava2s . c o m * @return */ private static ArrayMap<Triangle, Array<Edge>> createIsolatedEdgesMap( ArrayMap<Triangle, Array<Edge>> connectionMap) { ArrayMap<Triangle, Array<Edge>> disconnectionMap = new ArrayMap<Triangle, Array<Edge>>(); for (int i = 0; i < connectionMap.size; i++) { Triangle tri = connectionMap.getKeyAt(i); Array<Edge> connectedEdges = connectionMap.getValueAt(i); Array<Edge> disconnectedEdges = new Array<Edge>(); disconnectionMap.put(tri, disconnectedEdges); if (connectedEdges.size < 3) { // This triangle does not have all edges connected to other triangles boolean ab = true; boolean bc = true; boolean ca = true; for (Edge edge : connectedEdges) { if (edge.rightVertex == tri.a && edge.leftVertex == tri.b) ab = false; else if (edge.rightVertex == tri.b && edge.leftVertex == tri.c) bc = false; else if (edge.rightVertex == tri.c && edge.leftVertex == tri.a) ca = false; } if (ab) disconnectedEdges.add(new Edge(tri, null, tri.a, tri.b)); if (bc) disconnectedEdges.add(new Edge(tri, null, tri.b, tri.c)); if (ca) disconnectedEdges.add(new Edge(tri, null, tri.c, tri.a)); } int totalEdges = (connectedEdges.size + disconnectedEdges.size); if (totalEdges != 3) { Gdx.app.debug(TAG, "Wrong number of edges (" + totalEdges + ") in triangle " + tri.getIndex()); } } return disconnectionMap; }
From source file:com.mygdx.game.pathfinding.NavMeshGraph.java
License:Apache License
/** * Creates a map over each triangle and its Edge connections to other triangles. Each edge must follow the * vertex winding order of the triangle associated with it. Since all triangles are assumed to have the same * winding order, this means if two triangles connect, each must have its own edge connection data, where the * edge follows the same winding order as the triangle which owns the edge data. * * @param indexConnections//from w ww . j a va2 s . co m * @param triangles * @param vertexVectors * @return */ private static ArrayMap<Triangle, Array<Edge>> createSharedEdgesMap(Array<IndexConnection> indexConnections, Array<Triangle> triangles, Vector3[] vertexVectors) { ArrayMap<Triangle, Array<Edge>> connectionMap = new ArrayMap<Triangle, Array<Edge>>(); connectionMap.ordered = true; for (Triangle tri : triangles) { connectionMap.put(tri, new Array<Edge>()); } for (IndexConnection i : indexConnections) { Triangle fromNode = triangles.get(i.fromTriIndex); Triangle toNode = triangles.get(i.toTriIndex); Vector3 edgeVertexA = vertexVectors[i.edgeVertexIndex1]; Vector3 edgeVertexB = vertexVectors[i.edgeVertexIndex2]; Edge edge = new Edge(fromNode, toNode, edgeVertexA, edgeVertexB); connectionMap.get(fromNode).add(edge); fromNode.connections.add(edge); } return connectionMap; }
From source file:com.turbogerm.helljump.HellJump.java
License:Open Source License
private void initializeScreens() { mScreens = new ArrayMap<String, Screen>(); mScreens.put(SPLASH_SCREEN_NAME, new SplashScreen(this)); mScreens.put(MAIN_MENU_SCREEN_NAME, new MainMenuScreen(this)); mScreens.put(PLAY_SCREEN_NAME, new PlayScreen(this)); mScreens.put(HIGH_SCORE_SCREEN_NAME, new HighScoreScreen(this)); mScreens.put(CREDITS_SCREEN_NAME, new CreditsScreen(this)); mScreens.put(GAME_OVER_SCREEN_NAME, new GameOverScreen(this)); setScreen(SPLASH_SCREEN_NAME);// ww w . j a v a 2 s .c o m }
From source file:com.vlaaad.dice.game.objects.Obstacle.java
License:Open Source License
@Override public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) { ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>(); result.put(this, new ImageSubView("obstacle/" + worldObjectName)); return result; }
From source file:com.vlaaad.dice.game.objects.StepDetector.java
License:Open Source License
@Override public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) { ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>(); result.put(this, new StepDetectorSubView(this)); return result; }
From source file:com.vlaaad.dice.game.objects.WorldObject.java
License:Open Source License
public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) { ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>(); result.put(this, new ImageSubView(worldObjectName)); return result; }
From source file:de.tomgrill.gdxfacebook.core.utils.Utils.java
License:Apache License
public static ArrayMap<String, String> parseQuery(String query) throws UnsupportedEncodingException { ArrayMap<String, String> params = new ArrayMap<String, String>(); for (String param : query.split("&")) { String[] pair = param.split("="); String key = URLDecoder.decode(pair[0], "UTF-8"); String value = URLDecoder.decode(pair[1], "UTF-8"); params.put(key, value);/*from w w w . ja v a 2 s .c om*/ } return params; }