public void Draw(SpriteBatch spriteBatch,TileLayer fog_map)
 {
     foreach (Stair item in objectList)
     {
         if (fog_map.Map[(int)item.Position.Y / Engine.TileHeight, (int)item.Position.X / Engine.TileHeight] == -1)
             item.Draw(spriteBatch);
     }
 }
        public static TileLayer FromFile(ContentManager content, string filename)
        {
            TileLayer tileLayer;

            bool readingTexture=false;
            bool readingLayer = false;
            List<string> texturenames = new List<string>();
            List<List<int>> tempLayout = new List<List<int>>();

            using (StreamReader reader= new StreamReader(filename))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();

                    if (string.IsNullOrEmpty(line))
                        continue;

                    if (line.Contains("[Textures]"))
                    {
                        readingTexture = true;
                        readingLayer = false;
                    }
                    else if (line.Contains("[Layout]"))
                    {
                        readingTexture = false;
                        readingLayer = true;
                    }
                    else if (readingTexture)
                    {
                        texturenames.Add(line);
                    }
                    else if (readingLayer)
                    {
                        List<int>row = new List<int>();

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

                        foreach (string c in cells)
                        {
                            if (!string.IsNullOrEmpty(c))
                                row.Add(int.Parse(c));
                        }

                        tempLayout.Add(row);
                    }

                }
            }

            int width = tempLayout[0].Count;
            int height = tempLayout.Count;

            tileLayer = new TileLayer(width, height);
            string s = filename.Substring(filename.Length-7, 1);
            tileLayer.index = int.Parse(s);
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    tileLayer.SetCellIndex(x, y, tempLayout[y][x]);
                }
            }

            tileLayer.LoadTileTextures(content, texturenames.ToArray());

            return tileLayer;
        }
Example #3
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            tileLayer_map = TileLayer.FromFile(Content, "Content/Layers/world" + tileMapListIndex + ".layer");

            tileLayer_fog = TileLayer.FromFile(Content, "Content/Layers/fog" + tileMapListIndex + ".layer");
            tileLayer_fog.Alpha = 0.85f;

            tileMap.Layers.Add(tileLayer_map);
            tileMap.Layers.Add(tileLayer_fog);

            tileMapList.Add(tileMap);

            unAnimatedSprites = new UnAnimatedSprites();
            LoadSprites();

            InitializeNPCs();
        }