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);
        }
Exemple #2
0
        private void LoadTiles(CollisionLayer colLayer)
        {
            globalX = colLayer.Width;
            globalY = colLayer.Height;

            tiles = new Tile[colLayer.Width, colLayer.Height];

            for (int x = 0; x < colLayer.Width; ++x)
            {
                for (int y = 0; y < colLayer.Height; ++y)
                {
                    tiles[x, y] = LoadTile(colLayer.GetCellIndex(x, y), x, y);
                }
            }

            //if (exits.Count == 0)
            //    throw new NotSupportedException("A level must have an exit.");
        }