private static void CreateCollision(XmlNode currentNode, Tile current, int x, int y) { // if there is no innertext, collision is full cell if (currentNode.SelectSingleNode("Collision") != null && currentNode.SelectSingleNode("Collision").InnerText == string.Empty) { //full tiles current.CollisionBox.Add(new Rectangle(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE)); } else { //partial tiles if (currentNode.SelectSingleNode("Collision") != null) { var col = currentNode.SelectSingleNode("Collision").InnerText.Split(','); current.CollisionBox.Add(new Rectangle((x * TILE_SIZE) + int.Parse(col[0]), (y * TILE_SIZE) + int.Parse(col[1]), int.Parse(col[2]), int.Parse(col[3]))); } //walls if (current.Walls[0] == "1") current.CollisionBox.Add(new Rectangle(x * TILE_SIZE, y * TILE_SIZE, WALL_SIZE, TILE_SIZE)); if (current.Walls[1] == "1") current.CollisionBox.Add(new Rectangle(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, WALL_SIZE)); } }
public void LoadContent(string name) { var doc = new XmlDocument(); doc.Load("Content/Levels/" + name + ".xml"); var level = doc.SelectSingleNode("/Level"); var rows = level.SelectNodes("Row"); var c = rows[0].SelectNodes("Column"); Tiles = new Tile[c.Count, rows.Count]; for (int y = 0; y < rows.Count; y++) { var columns = rows[y].SelectNodes("Column"); for (int x = 0; x < columns.Count; x++) { var currentNode = rows[y].SelectNodes("Column")[x]; var current = new Tile { Image = _manager.Load<Texture2D>("gfx/Tiles/" + currentNode.SelectSingleNode("Tile").InnerText + ".png"), Walls = currentNode.SelectSingleNode("Walls") != null ? currentNode.SelectSingleNode("Walls").InnerText.Split(',') : new string[2], CollisionBox = new List<Rectangle>() }; CreateCollision(currentNode, current, x, y); current.Item = CreateItem(currentNode); CreateDoor(currentNode, x, y); Tiles[x, y] = current; } } FindWallCaps(); }