package de.samdev.colorrunner.game.world.map; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.XmlReader; import com.badlogic.gdx.utils.XmlReader.Element; public class CRTiledMap { public final static int GID_EMPTY = 0; public final static int GID_MID = 13; public final static int GID_UP = 8; public final static int GID_RIGHT = 14; public final static int GID_DOWN = 18; public final static int GID_LEFT = 12; public int width; public int height; public int[][] map; public static CRTiledMap load(String inputXmlString) { CRTiledMap result = new CRTiledMap(); XmlReader reader = new XmlReader(); Element root = reader.parse(inputXmlString); Element elemLayer = root.getChildByName("layer"); Element elemData = elemLayer.getChildByName("data"); Array tiles = elemData.getChildrenByName("tile"); int width = elemLayer.getInt("width"); int height = elemLayer.getInt("height"); result.map = new int[width][height]; result.width = width; result.height = height; for (int i = 0; i < tiles.size; i++) { result.map[i % width][i / width] = tiles.get(i).getInt("gid"); } return result; } public int getWidth() { return width; } public int getHeight() { return height; } public int getGID(int x, int y) { return map[x][y]; } }