Exemplo n.º 1
0
        public void LoadContent(Map map, string layerID)
        {
            tiles          = new List <List <Tile> >();
            attributes     = new List <List <string> >();
            contents       = new List <List <string> >();
            solid          = new List <string>();
            motion         = new List <string>();
            fileManager    = new FileManager();
            content        = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content");
            tileDimensions = new Vector2(32, 32);
            int layerYCount = 0;

            fileManager.LoadContent("Load/Maps/" + map.Id + ".cme", attributes, contents, layerID);
            string[] parts;
            for (int i = 0; i < attributes.Count; i++)
            {
                for (int j = 0; j < attributes[i].Count; j++)
                {
                    switch (attributes[i][j])
                    {
                    case "TileSet":
                        tileSheet = content.Load <Texture2D>(contents[i][j]);
                        break;

                    case "Solid":
                        solid.Add(contents[i][j]);
                        break;

                    case "Motion":
                        motion.Add(contents[i][j]);
                        break;

                    case "StartLayer":
                        if (contents[i][j].Contains("Generate"))
                        {
                            parts = contents[i][j].Split(':');
                            List <List <string> > mapCells = Generate(int.Parse(parts[1]), int.Parse(parts[2]),
                                                                      int.Parse(parts[3]), bool.Parse(parts[4]));
                            for (int l = 0; l < mapCells.Count; l++)
                            {
                                List <Tile> tempTiles  = new List <Tile>();
                                Tile.Motion tempMotion = Tile.Motion.Static;
                                Tile.State  tempState;
                                for (int k = 0; k < mapCells[l].Count; k++)
                                {
                                    parts = mapCells[l][k].Split(',');
                                    tempTiles.Add(new Tile());

                                    if (solid.Contains(mapCells[l][k]))
                                    {
                                        tempState = Tile.State.Solid;
                                    }
                                    else
                                    {
                                        tempState = Tile.State.Passive;
                                    }

                                    foreach (string m in motion)
                                    {
                                        if (m.Contains(mapCells[l][k]))
                                        {
                                            string[] getMotion = m.Split(':');
                                            tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]);
                                            break;
                                        }
                                    }
                                    tempTiles[k].SetTile(tempState, tempMotion, new Vector2(tileDimensions.X * k, tileDimensions.Y * l), tileSheet,
                                                         new Rectangle(int.Parse(parts[0]) * (int)tileDimensions.X, int.Parse(parts[1]) * (int)tileDimensions.Y, (int)tileDimensions.X, (int)tileDimensions.Y));
                                }
                                tiles.Add(tempTiles);
                            }
                        }
                        else
                        {
                            List <Tile> tempTiles  = new List <Tile>();
                            Tile.Motion tempMotion = Tile.Motion.Static;
                            Tile.State  tempState;
                            for (int k = 0; k < contents[i].Count; k++)
                            {
                                parts = contents[i][k].Split(',');
                                tempTiles.Add(new Tile());

                                if (parts[0] == "8" && parts[1] == "0")
                                {
                                    startingPoint = new Vector2(tileDimensions.X * k, tileDimensions.Y * layerYCount);
                                }

                                if (solid.Contains(contents[i][k]))
                                {
                                    tempState = Tile.State.Solid;
                                }
                                else
                                {
                                    tempState = Tile.State.Passive;
                                }

                                foreach (string m in motion)
                                {
                                    if (m.Contains(contents[i][k]))
                                    {
                                        string[] getMotion = m.Split(':');
                                        tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]);
                                        break;
                                    }
                                }
                                tempTiles[k].SetTile(tempState, tempMotion, new Vector2(tileDimensions.X * k, tileDimensions.Y * layerYCount), tileSheet,
                                                     new Rectangle(int.Parse(parts[0]) * (int)tileDimensions.X, int.Parse(parts[1]) * (int)tileDimensions.Y, (int)tileDimensions.X, (int)tileDimensions.Y));
                            }
                            layerYCount++;
                            tiles.Add(tempTiles);
                        }
                        break;
                    }
                }
            }
        }