示例#1
0
        private TileGrid GetTileset(string tilesetName)
        {
            TileGrid tileset = null;

            using (Bitmap sceneryTileset = GetImage("tilesets/" + tilesetName)) {
                tileset = new TileGrid(8, 8, sceneryTileset.Width / 8, sceneryTileset.Height / 8);
                tileset.Load(sceneryTileset);
            }
            return(tileset);
        }
示例#2
0
        public AutoTiler(string xmlDescription)
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml(xmlDescription);
            Dictionary <char, XmlElement> dictionary = new Dictionary <char, XmlElement>();

            foreach (object obj in document.GetElementsByTagName("Tileset"))
            {
                XmlElement xmlElement = (XmlElement)obj;
                char       c          = xmlElement.AttrChar("id");
                Bitmap     tileImages = Gameplay.GetImage("tilesets/" + xmlElement.Attr("path"));
                TileGrid   tileset    = new TileGrid(8, 8, tileImages.Width / 8, tileImages.Height / 8);
                tileset.Load(tileImages);
                TerrainType terrainType = new TerrainType(c);
                ReadInto(terrainType, tileset, xmlElement);

                if (xmlElement.HasAttr("copy"))
                {
                    char key = xmlElement.AttrChar("copy");
                    if (!dictionary.ContainsKey(key))
                    {
                        throw new Exception("Copied tilesets must be defined before the tilesets that copy them!");
                    }
                    ReadInto(terrainType, tileset, dictionary[key]);
                }

                if (xmlElement.HasAttr("ignores"))
                {
                    foreach (string text in xmlElement.Attr("ignores").Split(','))
                    {
                        if (text.Length > 0)
                        {
                            terrainType.Ignores.Add(text[0]);
                        }
                    }
                }

                dictionary.Add(c, xmlElement);
                lookup.Add(c, terrainType);
            }
        }