/** * Rendert alle Layer und alle Objekte * * @param deltaTime die Zeit, die seit dem letztem Frame vergangen ist */ public void renderAll(float deltaTime) { beginRender(); for (MapLayer layer : map.getLayers()) { if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { if (layer == displayLayer) renderDisplayLayer((TiledMapTileLayer) layer, deltaTime); else renderTileLayer((TiledMapTileLayer)layer); } else if (layer instanceof TiledMapImageLayer) { renderImageLayer((TiledMapImageLayer)layer); } else { renderObjects(layer); } } } endRender(); }
@Override public void update(final long elapsedTime) { timeInAnimation = (timeInAnimation + elapsedTime) % getTotalAnimationTimeMs(); final int frameIndex = (int) (timeInAnimation / timePerFrameMs); TiledMapTile currentTile = tileFrames.get(indexOrder[frameIndex]); for (MapLayer layer : tiledMap.getLayers()) { TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) layer; for (int x = 0; x < tiledMapLayer.getWidth(); x++) { for (int y = 0; y < tiledMapLayer.getHeight(); y++) { final TiledMapTileLayer.Cell cell = tiledMapLayer.getCell(x, y); if (cell != null) { TiledMapTile tile = cell.getTile(); final MapProperties tileProperties = tile.getProperties(); if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID) && tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) { cell.setTile(currentTile); } } } } } }
public static <T> T getCellPropertyFromTopMostTile(final TiledMap tiledMap, final TileCoordinate coordinate, final String propertyName, final Class<T> clazz) { T value = null; for (MapLayer mapLayer : tiledMap.getLayers()) { if (mapLayer instanceof TiledMapTileLayer && matchProperty(mapLayer, GameMap.MAP_LAYER_PROP_MAP_LAYER, coordinate.getMapLayer())) { TiledMapTileLayer tiledMapTileLayer = (TiledMapTileLayer) mapLayer; TiledMapTileLayer.Cell cell = tiledMapTileLayer.getCell(coordinate.getX(), coordinate.getY()); if (cell != null) { final MapProperties cellProps = cell.getTile().getProperties(); value = (cellProps.get(propertyName, clazz) != null) ? cellProps.get(propertyName, clazz) : value; } } } return value; }
public void load(TiledMap map) { MapProperties properties = map.getProperties(); width = (Integer) properties.get(Tmx.WIDTH); height = (Integer) properties.get(Tmx.HEIGHT); objects = new MapObject[width][height]; portals.clear(); for (MapLayer layer : map.getLayers()) { for (MapObject object : layer.getObjects()) { if (object.getProperties().get("portal-id") != null) { portals.put((String) object.getProperties().get("portal-id"), object); } MapProperties objectProperties = object.getProperties(); float x = (Float) objectProperties.get("x"); float y = (Float) objectProperties.get("y"); int indexX = (int) Math.floor(x / GameConfig.CELL_SCALE); int indexY = (int) Math.floor(y / GameConfig.CELL_SCALE); if (indexX >= 0 && indexY >= 0 && indexX < width && indexY < height) { objects[indexX][indexY] = object; } } } }
protected void renderLayersExcludingSpecial(float delta) { for (MapLayer layer : map.getTiledMap().getLayers()) { boolean groundLayer = layer.getProperties().get( GameMapLoader.PROPERTY_GROUND_LAYER) != null; boolean collisionLayer = layer.getProperties().get( GameMapLoader.PROPERTY_COLISIONS_LAYER) != null; boolean objectLayer = layer.getProperties().get( GameMapLoader.PROPERTY_OBJECT_LAYER) != null; boolean overheadLayer = layer.getProperties().get( GameMapLoader.PROPERTY_OVERHEAD_LAYER) != null; boolean alwaysAboveLayer = layer.getProperties().get( GameMapLoader.PROPERTY_ALWAYSABOVE_LAYER) != null; if (groundLayer || collisionLayer || objectLayer || overheadLayer || alwaysAboveLayer) { continue; } if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { renderTileLayer(delta, (TiledMapTileLayer) layer); } } } }
private void loadCharacterGroups() throws IOException { MapLayer groupsLayer = map.getLayers().get(LAYER_GROUPS); if (groupsLayer == null) { return; } MapObjects groups = groupsLayer.getObjects(); for (MapObject mapGroup : groups) { if (mapGroup.getName() == null) { continue; } String groupFile = mapGroup.getName(); String id = (String) mapGroup.getProperties().get(PROPERTY_ID); if (id == null) { id = groupFile; } Vector2 position = getPositionFromMapObject(mapGroup); CharacterGroupGameObject group = new CharacterGroupGameObject(id, Gdx.files.internal(Configuration .getFolderGroups() + groupFile + ".xml"), gameMap); group.position().set((int) (position.x / gameMap.getTileSizeX()), (int) (position.y / gameMap.getTileSizeY())); } }
private void loadItems() throws IOException { MapLayer itemsLayer = map.getLayers().get(LAYER_ITEMS); if (itemsLayer == null) { return; } MapObjects items = itemsLayer.getObjects(); for (MapObject item : items) { Vector2 position = getPositionFromMapObject(item); PickableGameObject newItem = new PickableGameObject(item.getName()); newItem.getOwner().set(item.getProperties().get(PROPERTY_OWNER_CHARACTER, String.class), Faction.getFaction(item.getProperties().get(PROPERTY_OWNER_FACTION, String.class)), Boolean.valueOf(item.getProperties().get(PROPERTY_OWNER_FIXED, "false", String.class))); newItem.position().set(position.x / gameMap.getTileSizeX(), position.y / gameMap.getTileSizeY()); newItem.setMap(gameMap); newItem.setOffsets(newItem.getXOffset() + getInteger(item, PROPERTY_XOFFSET, 0) * gameMap.getScaleX(), newItem.getYOffset() + getInteger(item, PROPERTY_YOFFSET, 0) * gameMap.getScaleY()); } }
private void loadLocations(MapLayer locationsLayer, boolean loadTraps) throws IOException { if (locationsLayer == null) { return; } MapObjects locations = locationsLayer.getObjects(); for (MapObject location : locations) { String locId = location.getProperties().get(PROPERTY_ID, location.getName(), String.class) .toLowerCase(Locale.ENGLISH); String locType = location.getName(); SaveablePolygon locPolygon = transformTiledPolygon(gameMap, getPolygonFromMapObject(location)); GameLocation newLocation = loadTraps ? new TrapLocation(locId, locType, locPolygon, Boolean.valueOf(location.getProperties().get(PROPERTY_DETECTED, "false", String.class)), Boolean.valueOf(location.getProperties().get(PROPERTY_DISARMED, "false", String.class))) : new GameLocation(locId, locType, locPolygon); newLocation.setMap(gameMap); newLocation.loadFromXML(Gdx.files.internal(Configuration.getFolderLocations() + locType + ".xml")); } for (GameObject go : gameMap.gameObjects) { if (go instanceof GameCharacter) { ((GameCharacter) go).calculateCurrentLocations(); } } }
private void loadTransitions() { MapLayer locationsLayer = map.getLayers().get(LAYER_TRANSITIONS); if (locationsLayer == null) { return; } Array<Transition> transitions = new Array<Transition>(); MapObjects locations = locationsLayer.getObjects(); for (MapObject location : locations) { MapObject mapObject = (MapObject) location; String[] coords = ((String) mapObject.getProperties().get(PROPERTY_TARGET)).split(","); Tile target = new Tile(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim())); Polygon polygon = getPolygonFromMapObject(mapObject); Transition newTransition = new Transition(gameMap, mapObject.getName(), target.getX(), target.getY(), transformTiledPolygon(gameMap, polygon)); transitions.add(newTransition); } buildTransitionTiles(transitions); }
public void populate(TiledMap tiledMap, State state, Camera camera, MapLayerRendererFactory rendererFactory, TiledMapConfig config) { MapLayers mapLayers = tiledMap.getLayers(); handleMapProperties(tiledMap.getProperties(), state, config); List<String> layerIds = new ArrayList<String>(); int lastTileLayerIndex = 0; for (int i = 0; i < mapLayers.getCount(); ++i) { MapLayer mapLayer = mapLayers.get(i); if (mapLayer instanceof TiledMapTileLayer) { if (i > 0) { lastTileLayerIndex++; } String layerId = handleTiledMapTileLayer((TiledMapTileLayer) mapLayer, i, tiledMap, camera, rendererFactory, config); layerIds.add(layerId); populateStaticMapData(lastTileLayerIndex, (TiledMapTileLayer) mapLayer, state, config); } else { // Not a tiledlayer so consider it as an object layer handleObjectLayer(lastTileLayerIndex, mapLayer, state, config); } } state.setLayerIds(layerIds); }
/** * @param map the {@link Map} which hierarchy to print * @return a human readable {@link String} containing the hierarchy of the {@link com.badlogic.gdx.maps.MapObjects} of the given {@link Map} */ public String getHierarchy(Map map) { String hierarchy = map.getClass().getName() + "\n", key, layerHierarchy; Iterator<String> keys = map.getProperties().getKeys(); while (keys.hasNext()) hierarchy += (key = keys.next()) + ": " + map.getProperties().get(key) + "\n"; for (MapLayer layer : map.getLayers()) { hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getName() + "):\n"; layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t"); layerHierarchy = layerHierarchy.endsWith("\n\t\t") ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t")) : layerHierarchy; hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy; } return hierarchy; }
public void loadLevelObjects() { MapLayer mapLayerMission = getMap().getLayers().get(LAYER_MISSIONOBJECTS); MapObjects objects = mapLayerMission.getObjects(); for (int i = 0; i < objects.getCount(); i++) { MapObject mapObj = objects.get(i); SpawnableBase base = EntityFactory.getEntity(mapObj.getName()); if (base != null) { base.prepareFromMap(getLevelID(), mapObj); } } Logger.dbg("map objects loaded!"); }
public void renderFG(SpriteBatch sb){ sb.begin(); if(foreground!=null) sb.draw(foreground, 0, 0); // sb.draw(weather,0,0); //if raining or foggy sb.end(); try{ for(MapLayer t : tileMap.getLayers()) if(t.getName().equals("fg")){ t.setVisible(true); } else t.setVisible(false); tmr.render(); }catch(Exception e){ e.printStackTrace(); } }
public void render(){ beginRender(); int layerCourant = 0; for(MapLayer layer : map.getLayers()){ if(layer instanceof TiledMapTileLayer){ renderTileLayer((TiledMapTileLayer)layer); layerCourant++; if(layerCourant==numberOfSpriteLayer){//if we are in the layer for the Sprite //just draw it up!!!! for(Sprite dropOfKoffee : superStrongKoffee){ System.out.println("Fuck OFFF!!!!"); dropOfKoffee.draw(this.batch); } } }else{ for(MapObject wtfIsThisObject : layer.getObjects()){ renderObject(wtfIsThisObject); } } } endRender(); }
protected void loadObjectGroup (TiledMap map, Element element) { if (element.getName().equals("objectgroup")) { String name = element.getAttribute("name", null); MapLayer layer = new MapLayer(); layer.setName(name); Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } for (Element objectElement : element.getChildrenByName("object")) { loadObject(layer, objectElement); } map.getLayers().add(layer); } }
public static void createCoins(Map map, MapLayer layer, Box2DWorld world) { Matrix4 transformMat4 = getTransformationMatrix(map); Vector3 coinPos = new Vector3(); for(MapObject object : layer.getObjects()) { if(object instanceof RectangleMapObject) { RectangleMapObject rectangleObj = (RectangleMapObject)object; // Get coin position from map object and transform it by transformation matrix coinPos.set(rectangleObj.getRectangle().getX() + rectangleObj.getRectangle().width / 2, rectangleObj.getRectangle().getY() + rectangleObj.getRectangle().height / 2, 0); coinPos.mul(transformMat4); // Create new Coin Coin newCoin = new Coin(coinPos.x, coinPos.y, world); // Add Coin entity to EntityManager map.getEntMan().addCoin(newCoin); } } }
public static Vector2 getPlayerPosition(Map map, MapLayer layer) { Vector2 playerPos = new Vector2(0,0); for(MapObject object : layer.getObjects()) { if(object instanceof EllipseMapObject) { EllipseMapObject mapObject = (EllipseMapObject)object; Vector3 tempVec3 = new Vector3(); tempVec3.set(mapObject.getEllipse().x + mapObject.getEllipse().width / 2, mapObject.getEllipse().y + mapObject.getEllipse().height / 2, 0); tempVec3.mul(getTransformationMatrix(map)); playerPos.set(tempVec3.x, tempVec3.y); } } return playerPos; }
private Array<Goomba> generateEnemies() { Array<Goomba> goombas = new Array<Goomba>(); MapLayer layer = map.getLayers().get("objects"); MapObjects objects = layer.getObjects(); Iterator<MapObject> objectIt = objects.iterator(); while(objectIt.hasNext()) { MapObject obj = objectIt.next(); String type = (String) obj.getProperties().get("type"); if(type != null) { float x = (Float) obj.getProperties().get("x"); float y = (Float) obj.getProperties().get("y"); if(type.equals("goomba")) { Goomba goomba = new Goomba(this, x * (1/16f), y* (1/16f)); goombas.add(goomba); stage.addActor(goomba); } } } return goombas; }
/** * Setup the flag at the end of the level * @param layer Tmx map layer with the object named 'flag'; */ private void generateFlag(MapLayer layer) { MapObject obj = layer.getObjects().get("flag"); float x = (Float) obj.getProperties().get("x") * World.scale; float y = (Float) obj.getProperties().get("y") * World.scale; float width = Float.valueOf((String) obj.getProperties().get("width")); float height = Float.valueOf((String) obj.getProperties().get("height")); // The object in the map named 'flag_end' determines the position Mario walks to after the flag MapObject flag_end = layer.getObjects().get("flag_end"); float flag_end_x = (Float) flag_end.getProperties().get("x") * World.scale; float flag_end_y = (Float) flag_end.getProperties().get("y") * World.scale; flag = new Flag(x, y, width, height, flag_end_x, flag_end_y); stage.addActor(flag); }
/** * Check if there are items in a brick, if there are they are added to the brick. * @param brick * @param x * @param y */ private void itemsInBrick(Brick brick, int x, int y) { MapLayer layer = map.getLayers().get("hidden_items"); MapObjects objects = layer.getObjects(); for(MapObject obj : objects) { int obj_x = (int) ((Float) obj.getProperties().get("x") * (1/16f)); int obj_y = (int) ((Float) obj.getProperties().get("y") * (1/16f)); if(obj_x == x && obj_y == y) { String type = (String) obj.getProperties().get("type"); Actor item = null; if(type.equals("super_mushroom")) { item = new Super(this, x, y, 4f); mushrooms.add((Mushroom) item); } stage.addActor(item); brick.addItem(item); } } }
/** * @param map the {@link Map} which hierarchy to print * @return a human readable {@link String} containing the hierarchy of the {@link MapObjects} of the given {@link Map} */ public String getHierarchy(Map map) { String hierarchy = map.getClass().getName() + "\n", key, layerHierarchy; Iterator<String> keys = map.getProperties().getKeys(); while (keys.hasNext()) hierarchy += (key = keys.next()) + ": " + map.getProperties().get(key) + "\n"; for (MapLayer layer : map.getLayers()) { hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getName() + "):\n"; layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t"); layerHierarchy = layerHierarchy.endsWith("\n\t\t") ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t")) : layerHierarchy; hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy; } return hierarchy; }
/** * Loads the layers of a map. * * @return true if the map layers were correctly loaded, false otherwise. */ Boolean load() { MapLayer layer = map.getLayers().get(name); if (layer == null) return false; for (T object : layer.getObjects().getByType(type)) { loadObject(world, object); } return true; }
@Override protected void processSystem() { for (MapLayer layer : mapSystem.map.getLayers()) { if (layer.isVisible()) { if (layer.getName().equals("infront")) { renderLayer((TiledMapTileLayer) layer); } } } }
@Override protected void initialize() { map = new TmxMapLoader().load("map" + G.level + ".tmx"); layers = new Array<TiledMapTileLayer>(); for (MapLayer rawLayer : map.getLayers()) { layers.add((TiledMapTileLayer) rawLayer); } width = layers.get(0).getWidth(); height = layers.get(0).getHeight(); // need to do this before we purge the indicators from the map. mapCollisionSystem.canHoverMask = getMask("canhover"); mapCollisionSystem.deadlyMask = getMask("deadly"); mapCollisionSystem.solidForRobotMask = getMask("solidforrobot"); for (TiledMapTileSet tileSet : map.getTileSets()) { for (TiledMapTile tile : tileSet) { final MapProperties props = tile.getProperties(); if (props.containsKey("entity")) { Animation<TextureRegion> anim = new Animation<>(10, tile.getTextureRegion()); String id = (String) props.get("entity"); if (props.containsKey("cable-type")) { id = cableIdentifier(tile); } else if (props.containsKey("powered")) { id = props.get("entity") + "_" + (((Boolean) props.get("powered")) ? "on" : "off"); if (props.containsKey("accept")) { id = id + "_" + props.get("accept"); } } assetSystem.sprites.put(id, anim); } } } }
@Override protected void processSystem() { for (MapLayer layer : mapSystem.map.getLayers()) { if (layer.isVisible()) { if (!layer.getName().equals("infront")) { renderLayer((TiledMapTileLayer) layer); } } } }
private void loadUi(MapLayer layer, TextureAtlas atlas) { MapObjects objects = layer.getObjects(); Array<String> added = new Array<String>(); for (MapObject o : objects) { MapProperties properties = o.getProperties(); Actor ui_actor = getUiActor(added, o, properties, objects, atlas); if (ui_actor != null) uiground.addActor(ui_actor); } }
/** * Erzeugt aus einem ObjectLayer Box2D Körper. * * @param layer die Ebene * @param world die Box2D Welt */ public static void buildBodiesFromLayer(MapLayer layer, World world) { for(MapObject tileObject : layer.getObjects()) { if ( tileObject instanceof TextureMapObject || tileObject instanceof CircleMapObject || tileObject instanceof EllipseMapObject) continue; Shape shape = createShape(tileObject, TYPE_COLLISION); if (shape == null) continue; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; Body body = world.createBody(bodyDef); FixtureDef fixture = new FixtureDef(); fixture.shape = shape; fixture.filter.categoryBits = Physics.CATEGORY_WORLD; fixture.filter.maskBits = Physics.MASK_WORLD; body.createFixture(fixture); shape.dispose(); } }
/** * Parst die Map: Sucht nach Objekten mit denen der Spieler oder andere Objekte kollidieren. * * Wird von {@link #parseMap()} ()} aufgerufen. */ private void parseMapCollisionTiles() { MapLayer colLayer = tileMap.getLayers().get(LevelConstants.TMX_COLLISION_LAYER); if (colLayer == null) return; PhysicsTileMapBuilder.buildBodiesFromLayer(colLayer, physicalWorld); tileMap.getLayers().remove(colLayer); }
protected MapController loadObjects(){ for(MapLayer layer : map.getLayers()){ final String name = layer.getName(); final GameEntityType currenType = getTypeByLayer(name); for(MapObject object : layer.getObjects()) { GameEntity gameEntity = generateEntityByObject(object, currenType); } } return this; }
private boolean getCollision(TiledMap map, int x, int y) { boolean value = true; boolean npc = false; for (MapLayer layer : map.getLayers()) { for (MapObject o : layer.getObjects()) { MapProperties p = o.getProperties(); if (p.get(Tmx.TYPE) != null && p.get(Tmx.TYPE).equals(Tmx.NPC)) { float oX = (Float)p.get(Tmx.X) + GameConfig.CELL_SCALE / 2f; float oY = (Float)p.get(Tmx.Y) + GameConfig.CELL_SCALE / 2f; // Normalize spawn position oX = (int)Math.floor(oX / GameConfig.CELL_SCALE); oY = (int)Math.floor(oY / GameConfig.CELL_SCALE); if (oX == x && oY == y) { value = true; npc = true; } } } if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tiledLayer = (TiledMapTileLayer) layer; TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y); if (cell != null && cell.getTile() != null) { MapProperties properties = cell.getTile().getProperties(); boolean collision = Boolean.valueOf(properties.get(Tmx.COLLISION, "true", String.class)); if (!collision && !npc) { value = false; } } } } return value; }
public WorldRenderer(World world) { shapeDebugger = new ShapeRenderer(); this.world = world; //loadAssets(); Assets.init(); initGameObjects(); batch = new SpriteBatch(); camera = new OrthographicCamera(); camera.setToOrtho(false, Gdx.graphics.getWidth() / (float) World.TILE_SIZE, Gdx.graphics.getHeight() / (float) World.TILE_SIZE); camera.zoom += 2; //GUI camera gestureBatch = new SpriteBatch(); cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT); cameraGUI.position.set(0, 0, 0); cameraGUI.setToOrtho(false); //flip y-axis font = new BitmapFont(Gdx.files.internal("mainmenu/default.fnt"), Gdx.files.internal("mainmenu/default.png"), false); tileMapRenderer = new OrthogonalTiledMapRenderer(world.map, 1f / World.TILE_SIZE, batch); // figure out which layer has which id, idiotic for (int i = 0; i < world.map.getLayers().getCount(); i++) { MapLayer layer = world.map.getLayers().get(i); if (layer.getName().equals("floor")) LAYER_FLOOR = i; } }
public MapLayerWrapper(ColoredOrthogonalTiledMapRenderer renderer, MapLayer rawLayer) { this.renderer = renderer; if (rawLayer instanceof TiledMapTileLayer) { correctCells((TiledMapTileLayer)rawLayer); } this.rawLayer = rawLayer; }
private void parsePortalLayer(MapLayer layer) { if (layer == null) { Gdx.app.debug(TAG, "No portal layer!"); return; } for (MapObject object : layer.getObjects()) { if (object instanceof RectangleMapObject) { final Rectangle rect = ((RectangleMapObject) object).getRectangle(); if (START_LOCATION.equals(object.getName())) { rect.getPosition(startLocation); startLocation.scl(GameWorld.UNIT_SCALE); } else { portals.add(new Portal( rect.set( // update Tiled editor real values with our game world values rect.x * GameWorld.UNIT_SCALE, // scale x rect.y * GameWorld.UNIT_SCALE, // scale y rect.width * GameWorld.UNIT_SCALE, // scale width rect.height * GameWorld.UNIT_SCALE), // scale height, MapType.valueOf(object.getName()), // target map (int) (Integer.parseInt(object.getProperties().get("targetX", String.class)) * tileSize.x), // target tile index x (int) (Integer.parseInt(object.getProperties().get("targetY", String.class)) * tileSize.y)) // target tile index y ); } } } }
protected void renderTileLayers(float delta, Array<TiledMapTileLayer> layers) { for (MapLayer layer : layers) { if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { renderTileLayer(delta, (TiledMapTileLayer) layer); } } } }
protected void renderLayersExcludingColisions (float delta) { for (MapLayer layer : map.getTiledMap().getLayers()) { boolean collisionLayer = layer.getProperties().get(GameMapLoader.PROPERTY_COLISIONS_LAYER) != null; if (collisionLayer) { continue; } if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { renderTileLayer(delta, (TiledMapTileLayer) layer); } } } }
private void calculateMoveCosts() { Cell cell; int width = map.getProperties().get("width", Integer.class); int height = map.getProperties().get("height", Integer.class); gameMap.moveCosts = new float[width * height]; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { float moveCost = -1; for (MapLayer layer : gameMap.getTiledMap().getLayers()) { if (layer instanceof TiledMapTileLayer) { cell = ((TiledMapTileLayer) layer).getCell(x, y); if (cell != null) { MapProperties tileProperties = cell.getTile().getProperties(); Object cost = tileProperties.get(GameMapLoader.PROPERTY_MOVE_COST); if (cost != null) { float newCost = Float.valueOf((String) cost); if (newCost > moveCost) { moveCost = newCost; } } } } } if (moveCost < 0) { moveCost = 1; } gameMap.moveCosts[x + y * width] = moveCost; } } }
private void loadUsables() throws IOException { MapLayer itemsLayer = map.getLayers().get(LAYER_USABLES); if (itemsLayer == null) { return; } MapObjects items = itemsLayer.getObjects(); for (MapObject item : items) { Polygon polygon = getPolygonFromMapObject(item); if (item.getName() == null) { continue; } String type = item.getName(); Object idValue = item.getProperties().get(PROPERTY_ID); String id = idValue instanceof String ? (String) idValue : null; if (id == null) { id = type; } UsableGameObject newItem = new UsableGameObject(id, Gdx.files.internal(Configuration.getFolderUsables() + type + ".xml"), transformTiledPolygon(gameMap, polygon), gameMap); String orientationProp = item.getProperties().get(PROPERTY_ORIENTATION, null, String.class); if (orientationProp != null) { newItem.setOrientation(Orientation.valueOf(orientationProp.toUpperCase(Locale.ENGLISH))); } String groundProp = item.getProperties().get(PROPERTY_GROUND, null, String.class); if (groundProp != null) { String[] coords = groundProp.split(","); newItem.setGround(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim())); } newItem.setOffsets(newItem.getXOffset() + getInteger(item, PROPERTY_XOFFSET, 0) * gameMap.getScaleX(), newItem.getYOffset() + getInteger(item, PROPERTY_YOFFSET, 0) * gameMap.getScaleY()); } }
private void loadLocations() throws IOException { for (MapLayer layer : map.getLayers()) { if (LAYER_LOCATIONS.equals(layer.getName()) || layer.getProperties().get(PROPERTY_LOCATIONS_LAYER) != null) { loadLocations(layer, false); } } }
/** * Returns the coordinates where the PCs should * appear when they enter this map. * * @return */ public Vector2 getStartCoordinates() { if (startCoordinates == null) { MapLayer npcLayer = tiledMap.getLayers().get(LAYER_SPECIAL); if (npcLayer != null && npcLayer.getObjects().getCount() > 0) { MapObject startLocation = npcLayer.getObjects().get(0); if (startLocation instanceof EllipseMapObject) { Ellipse center = ((EllipseMapObject)startLocation).getEllipse(); startCoordinates = new Vector2((int)(center.x/getTileSizeX()), (int)(center.y/getTileSizeY())); } } } return startCoordinates; }