Пример #1
0
        public static CollisionLayer FromFile(string filename)
        {
            CollisionLayer     tileLayer;
            List <List <int> > tempLayout = new List <List <int> >();

            Dictionary <int, string> tempHold = new Dictionary <int, string>();

            XmlDocument input = new XmlDocument();

            input.Load(filename);

            int width  = 0;
            int height = 0;

            tileLayer = new CollisionLayer(width, height);

            foreach (XmlNode node in input.DocumentElement.ChildNodes)
            {
                if (node.Name == "Layout")
                {
                    width  = int.Parse(node.Attributes["Width"].Value);
                    height = int.Parse(node.Attributes["Height"].Value);

                    tileLayer = new CollisionLayer(width, height);

                    string layout = node.InnerText;

                    string[] lines = layout.Split('\r', '\n');

                    int row = 0;

                    foreach (string line in lines)
                    {
                        string realLine = line.Trim();

                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }

                        string[] cells = realLine.Split(' ');

                        for (int x = 0; x < width; x++)
                        {
                            string cellIndex = cells[x];
                            tileLayer.SetCellIndex(x, row, cellIndex);
                        }

                        row++;
                    }
                }
            }
            return(tileLayer);
        }