public GameEntity zzdN(Parcel parcel) { if (GameEntity.zzc(GameEntity.zztC()) || GameEntity.zzcV(com/google/android/gms/games/GameEntity.getCanonicalName())) { return super.zzdN(parcel); } String s = parcel.readString(); String s1 = parcel.readString(); String s2 = parcel.readString(); String s3 = parcel.readString(); String s4 = parcel.readString(); String s5 = parcel.readString(); Object obj = parcel.readString(); Object obj1; Object obj2; boolean flag; boolean flag1; if (obj == null) { obj = null; } else { obj = Uri.parse(((String) (obj))); } obj1 = parcel.readString(); if (obj1 == null) { obj1 = null; } else { obj1 = Uri.parse(((String) (obj1))); } obj2 = parcel.readString(); if (obj2 == null) { obj2 = null; } else { obj2 = Uri.parse(((String) (obj2))); } if (parcel.readInt() > 0) { flag = true; } else { flag = false; } if (parcel.readInt() > 0) { flag1 = true; } else { flag1 = false; } return new GameEntity(7, s, s1, s2, s3, s4, s5, ((Uri) (obj)), ((Uri) (obj1)), ((Uri) (obj2)), flag, flag1, parcel.readString(), parcel.readInt(), parcel.readInt(), parcel.readInt(), false, false, null, null, null, false, false, false, null, false); }
public TimeComponent(GameEntity owner, GameSystem gameSystem, Object[] arguments) { super(owner, gameSystem); owner.addComponent(this); gameSystem.registerComponent(this); init(arguments); }
@Override public void act(float delta) { super.act(delta); if (activeCounter < activeTime) { spawnParticles(); activeCounter += delta; } }
/** Create a monster randomly picked from all enemy types. */ public static GameEntity createRandomEnemy( GameSystem gameSystem, AreaComponent areaComponent, int level) { // Select a random key and value set from the enemy info Map Random random = new Random(); List<String> keys = new ArrayList<String>(enemyInfoMap.keySet()); String randomKey = keys.get(random.nextInt(keys.size())); Stats pick = enemyInfoMap.get(randomKey); // Use it to create the monster by passing the name GameEntity entity = createEnemy(gameSystem, pick.getName(), areaComponent, level); // Assign a random stats modifier StatsModifier randomStatsModifier = getRandomStatsModifier(); gameSystem.getCharacterComponent(entity.getID()).setStatsModifier(randomStatsModifier); return entity; }
/** * Loads from an external file a new GameMap object for use within the game. A GameMap is the * primary object which house each MapCanvas object (that is, each elevation level in the map) and * in turn, each MapTile object (that is, each unique texture block). * * @param file * @return The newly created GameMap */ public void loadMap(String file) { XMLParser mapFile = new XMLParser(file); for (Node mapEl : mapFile.root.children) { for (Node el : mapEl.children) { if (el.name.equals("tileDimensions")) GameMap.MAP.setTileDimension(el.readInt()); else if (el.name.equals("lightLevel")) GameMap.MAP.setLightLevel(el.readFloat()); else if (el.name.equals("tile")) { MapTile mt = new MapTile(); for (Node tileChild : el.children) { if (tileChild.name.equals("id")) mt.id = tileChild.readInt(); else if (tileChild.name.equals("file")) mt.loadTexture(tileChild.readString()); else if (tileChild.name.equals("collidable")) mt.collidable = tileChild.readBoolean(); } mt.width = mt.height = GameMap.MAP.tileDimensions; GameMap.MAP.tiles.put(mt.id, mt); } else if (el.name.equals("canvas")) GameMap.MAP.parseCanvas(el.data); else if (el.name.equals("entity")) { GameEntity entity = null; for (Node entityEl : el.children) { if (entityEl.name.equals("file")) { entity = loadEntity(entityEl.readString()); } else if (entityEl.name.equals("position")) entity.setPosition(entityEl.readFloatArray()); } addEntity(entity); } else if (el.name.equals("player")) { for (Node playerNode : el.children) { if (playerNode.name.equals("position")) MANAGER.playerFocusEntity.setPosition(playerNode.readFloatArray()); } } } } }
/** * Loads from an external resource file a new GameEntity object for use within the game. This * method will parse the given XML file and instantiate a new GameEntity object, returning it to * the calling context. * * @param file * @return The newly created GameEntity */ public GameEntity loadEntity(String file) { XMLParser entityFile = new XMLParser(file); GameEntity entity = new GameEntity(); entity.setFile(file); for (Node entityEl : entityFile.root.children) { for (Node el : entityEl.children) { if (el.name.equals("position")) entity.setPosition(el.readFloatArray()); else if (el.name.equals("width")) entity.setWidth(el.readInt()); else if (el.name.equals("height")) entity.setHeight(el.readInt()); else if (el.name.equals("mass")) entity.setMass(el.readFloat()); else if (el.name.equals("animationFile")) { entity.setAnimationFile(el.readString()); } else if (el.name.equals("scriptFile")) { entity.setScriptFile(el.readString()); } else if (el.name.equals("lightRadius")) entity.setLightRadius(el.readFloat()); } } return entity; }
public static void interpolateTimeStep(float alphaTime) { Physics.alphaTime = alphaTime; for (GameEntity gameEntity : EntityManager.gameEntities) { if (gameEntity.isNullBody() || isWorldLocked()) continue; Transform transform = gameEntity.getBody().getTransform(); Vector2 bodyPosition = transform.getPosition(); Vector2 position = gameEntity.getBody().getPosition(); float angle = gameEntity.getBody().getAngle(); float bodyAngle = transform.getRotation(); position.x = bodyPosition.x * alphaTime + position.x * (1.0f - alphaTime); position.y = bodyPosition.y * alphaTime + position.y * (1.0f - alphaTime); gameEntity .getBody() .setTransform(position, (bodyAngle * alphaTime + angle * (1.0f - alphaTime))); } }
public void addEntity(GameEntity ge) { ge.id = MANAGER.gameEntities.size() + 1; MANAGER.gameEntities.add(ge); }
// Get the ID's of the cells public int[] getCellIDs(GameEntity ent) { // Get the bottom left corner of the entity float entLowerX = ((ent.getPos().x + widthOffset) - (ent.getWidth() / 2)); float entLowerY = ((ent.getPos().y + heightOffset) - (ent.getHeight() / 2)); // Find which cell each corner is in int x1 = (int) Math.floor(entLowerX / cellSize); int y1 = (int) Math.floor(entLowerY / cellSize); int x2 = (int) Math.floor(entLowerX + ent.getWidth()); int y2 = (int) Math.floor(entLowerY + ent.getHeight()); // First check if the entity is in one cell if (x1 == x2 && y1 == y2) { if (x1 >= 0 && x1 < cellsInRow && y1 >= 0 && y1 < cellsInCol) { // The entity is in one cell cellID[0] = x1 + y1 * cellsInRow; } else { // The entity is in no cells cellID[0] = -1; } // The entity cannot be in any more cells cellID[1] = -1; cellID[2] = -1; cellID[3] = -1; } // Else if the entity is in two cells above or below else if (x1 == x2) { int i = 0; if (x1 >= 0 && x1 < cellsInRow) { if (y1 >= 0 && y1 < cellsInCol) { cellID[i++] = x1 + y1 * cellsInRow; } if (y2 >= 0 && y2 < cellsInCol) { cellID[i++] = x1 + y2 * cellsInRow; } } while (i <= 3) cellID[i++] = -1; } // Else if the entity is in two cells side by side else if (y1 == y2) { int i = 0; if (y1 >= 0 && y1 < cellsInCol) { if (x1 >= 0 && x1 < cellsInRow) { cellID[i++] = x1 + y1 * cellsInRow; } if (x2 >= 0 && x2 < cellsInRow) { cellID[i++] = x2 + y1 * cellsInRow; } while (i <= 3) { cellID[i++] = -1; } } } // Else if the entity is in four different cells else { int i = 0; int y1CellsRow = y1 * cellsInRow; int y2CellsRow = y2 * cellsInRow; if (x1 >= 0 && x1 < cellsInRow && y1 >= 0 && y1 < cellsInCol) { cellID[i++] = x1 + y1CellsRow; } if (x2 >= 0 && x2 < cellsInRow && y1 >= 0 && y1 < cellsInCol) { cellID[i++] = x2 + y1CellsRow; } if (x2 >= 0 && x2 < cellsInRow && y2 >= 0 && y2 < cellsInCol) { cellID[i++] = x2 + y2CellsRow; } if (x1 >= 0 && x1 < cellsInRow && y2 >= 0 && y2 < cellsInCol) { cellID[i++] = x1 + y2CellsRow; } while (i <= 3) { cellID[i++] = -1; } } return cellID; }
public void draw(Graphics g) { g.setColor(Color.GREEN); super.draw(g); }