Beispiel #1
0
        public void LoadContent(Map map, string layerID)
        {
            tiles       = new List <Tile>();
            motion      = new List <string>();
            solid       = new List <string>();
            fileManager = new FileManager();
            content     = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content");
            // setting up the filename and identifier for map1.txt
            fileManager.LoadContent("Load/Maps/" + map.ID + ".txt", layerID);

            int indexY = 0;

            // switch case for the different values within the map1.txt
            for (int i = 0; i < fileManager.Attributes.Count; i++)
            {
                for (int j = 0; j < fileManager.Attributes[i].Count; j++)
                {
                    switch (fileManager.Attributes[i][j])
                    {
                    case "TileSet":
                        tileSheet = content.Load <Texture2D>("TileSets/" + fileManager.Contents[i][j]);
                        break;

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

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

                    case "NullTile":
                        nullTile = fileManager.Contents[i][j];
                        break;

                    case "StartLayer":
                        Tile.Motion tempMotion = Tile.Motion.Static;
                        Tile.State  tempState;

                        for (int k = 0; k < fileManager.Contents[i].Count; k++)
                        {
                            // settings for wether the tiles will be solid or passive
                            if (fileManager.Contents[i][k] != nullTile)
                            {
                                string[] split = fileManager.Contents[i][k].Split(',');
                                tiles.Add(new Tile());

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

                                foreach (string m in motion)
                                {
                                    // settings for motion of the tiles
                                    getMotion = m.Split(':');
                                    if (getMotion[0] == fileManager.Contents[i][k])
                                    {
                                        tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]);
                                        break;
                                    }
                                }

                                tiles[tiles.Count - 1].SetTile(tempState, tempMotion, new Vector2(k * 32, indexY * 32), tileSheet,
                                                               new Rectangle(int.Parse(split[0]) * 32, int.Parse(split[1]) * 32, 32, 32));
                            }
                        }
                        indexY++;
                        break;
                    }
                }
            }
        }
Beispiel #2
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;
                    }
                }
            }
        }
Beispiel #3
0
        public void LoadContent(Map map, string layerID)
        {
            tiles       = new List <Tile>();
            attributes  = new List <List <string> >();
            contents    = new List <List <string> >();
            motion      = new List <string>();
            solid       = new List <string>();
            fileManager = new FileManager();
            content     = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content");

            fileManager.LoadContent("Load/Maps/" + map.ID + ".txt", attributes, contents, layerID);

            int indexY = 0;

            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>("TileSets/" + contents[i][j]);
                        break;

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

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

                    case "NullTile":
                        nullTile = contents[i][j];
                        break;

                    case "StartLayer":
                        Tile.Motion tempMotion = Tile.Motion.Static;
                        Tile.State  tempState;

                        for (int k = 0; k < contents[i].Count; k++)
                        {
                            if (contents[i][k] != nullTile)
                            {
                                string[] split = contents[i][k].Split(',');
                                tiles.Add(new Tile());

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

                                foreach (string m in motion)
                                {
                                    getMotion = m.Split(':');
                                    if (getMotion[0] == contents[i][k])
                                    {
                                        tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]);
                                        break;
                                    }
                                }

                                tiles[tiles.Count - 1].SetTile(tempState, tempMotion, new Vector2(k * TileDimensions.X, indexY * TileDimensions.X), tileSheet,      //tile dimensions are here
                                                               new Rectangle(int.Parse(split[0]) * 16, int.Parse(split[1]) * 16, 16, 16));
                            }
                        }
                        indexY++;
                        break;
                    }
                }
            }
        }
Beispiel #4
0
        public void LoadContent(Map map, string layerID)
        {
            tiles       = new List <List <Tile> >();
            attributes  = new List <List <string> >();
            contents    = new List <List <string> >();
            fileManager = new FileManager();
            motion      = new List <string>();
            solid       = new List <string>();
            trap        = new List <string>();
            door1       = new List <string>();
            key         = new List <string>();
            content     = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content");

            fileManager.LoadContent($"Load/{map.ID}.vke", attributes, contents);
            int indexY = 0;

            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 "Key":
                        key.Add(contents[i][j]);
                        break;

                    case "Trap":
                        trap.Add(contents[i][j]);
                        break;

                    case "Door1":
                        door1.Add(contents[i][j]);
                        break;

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

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

                    case "StartLayer":
                        List <Tile> tempTiles  = new List <Tile>();
                        Tile.Motion tempMotion = Tile.Motion.Static;
                        Tile.State  tempState;

                        for (int k = 0; k < contents[i].Count; k++)
                        {
                            string[] split = contents[i][k].Split(',');
                            tempTiles.Add(new Tile());



                            if (solid.Contains(contents[i][k]))
                            {
                                tempState = Tile.State.Solid;
                            }
                            else if (trap.Contains(contents[i][k]))
                            {
                                tempState = Tile.State.Trap;
                            }
                            else if (door1.Contains(contents[i][k]))
                            {
                                tempState = Tile.State.Door;
                            }
                            else if (key.Contains(contents[i][k]))
                            {
                                tempState = Tile.State.Key;
                            }

                            else
                            {
                                tempState = Tile.State.Passive;
                            }


                            foreach (string m in motion)
                            {
                                getMotion = m.Split(':');
                                if (getMotion[0] == contents[i][k])
                                {
                                    tempMotion = (Tile.Motion)Enum.Parse(typeof(Tile.Motion), getMotion[1]);
                                    break;
                                }
                            }

                            tempTiles[k].SetTile(tempState, tempMotion, new Vector2(k * 40, indexY * 40), tileSheet,
                                                 new Rectangle(int.Parse(split[0]) * 40, int.Parse(split[1]) * 40, 40, 40));
                        }
                        tiles.Add(tempTiles);
                        indexY++;
                        break;
                    }
                }
            }
        }