public TileMap opentilemap(string filename) { int mapwidth = 0; int mapheight = 0; TileMap map = null; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(filename); XmlNode declaration = xmldoc.FirstChild; XmlNode rootNode = xmldoc.ChildNodes[1]; if (!rootNode.Name.Equals("GameMap")) { throw new Exception("XML document is not formatted correctly"); } XmlNode layers = rootNode.FirstChild; if (!layers.Name.Equals("Layers")) { throw new Exception("XML document is not formatted correctly"); } for (int i = 0; i < layers.ChildNodes.Count; i++) { XmlNode layer = layers.ChildNodes[i]; if (!layer.Name.Equals("Layer")) { throw new Exception("XML document is not formatted correctly"); } //Rows uitlezen XmlNode rows = layer.FirstChild; if (!rows.Name.Equals("Rows")) { throw new Exception("XML document is not formatted correctly"); } XmlNode row = rows.FirstChild; if (!row.Name.Equals("row")) { throw new Exception("XML document is not formatted correctly"); } mapheight = rows.ChildNodes.Count; mapwidth = row.InnerText.Split(',').Count(); if(i == 0)map = new TileMap(mapwidth, mapheight); for (int r = 0; r < rows.ChildNodes.Count; r++) { string[] tiles = rows.ChildNodes[r].InnerText.Split(','); for (int c = 0; c < mapwidth; c++) { map.layers[i].SetTile(c, r, int.Parse(tiles[c])); } } } return map; }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openfile = new OpenFileDialog(); //savefile.InitialDirectory = "../Tilesets"; openfile.Filter = "XML Document (*.xml)|*.xml"; openfile.Title = "Save map"; if (openfile.ShowDialog() == DialogResult.OK) { Players.Clear(); tileMap = new TileMap.TileMap(1, 1); tileMap = tileMap.opentilemap(openfile.FileName); //load Collisionmap PathfindingNodeManager.GetInstance().ClearNodes(); CollisionMap = new CollisionMap(GraphicsDevice, tileMap.MapWidth * Engine.TileWidth, tileMap.MapHeight * Engine.TileHeight, true, Util.GetQuadDepth(tileMap.MapWidth)); CollisionMap.LoadMap(openfile.FileName.Substring(0, openfile.FileName.LastIndexOf('\\')), openfile.FileName.Substring(openfile.FileName.LastIndexOf('\\')).Replace(".xml", "")); PathfindingNodeManager.GetInstance().ClearNodes(); Util.LoadNodes(openfile.FileName, GraphicsDevice); Util.LoadPlayers(openfile.FileName); CollisionData = new int[(tileMap.MapWidth * Engine.TileWidth) * (tileMap.MapHeight * Engine.TileHeight)]; currentLayer = tileMap.layers[0]; } }
private void createNewMap() { //get values from newmapform tileMap = new TileMap.TileMap(mapform.MapWidth, mapform.MapHeight); CollisionMap = new Texture2D(GraphicsDevice, mapform.MapWidth * Engine.TileWidth, mapform.MapHeight * Engine.TileHeight); CollisionData = new int[(mapform.MapWidth * Engine.TileWidth) * (mapform.MapHeight * Engine.TileHeight)]; currentLayer = tileMap.layers[0]; }
private void createNewMap() { //get values from newmapform tileMap = new TileMap.TileMap(mapform.MapWidth, mapform.MapHeight); CollisionMap = new CollisionMap(GraphicsDevice, mapform.MapWidth * Engine.TileWidth, mapform.MapHeight * Engine.TileHeight,true,Util.GetQuadDepth(mapform.MapWidth)); //CollisionData = new int[(mapform.MapWidth * Engine.TileWidth) * (mapform.MapHeight * Engine.TileHeight)]; currentLayer = tileMap.layers[0]; Players.Clear(); PathfindingNodeManager.GetInstance().ClearNodes(); }