Exemple #1
0
 private CorvusScene(LevelData Data, string Name, GameState State)
     : base(Data, State)
 {
     this._Name = Name;
 }
Exemple #2
0
        /// <summary>
        /// Loads the data for a level using the Tiled Map Xml format.
        /// </summary>
        public static LevelData LoadTmx(string FilePath)
        {
            // https://github.com/bjorn/tiled/wiki/TMX-Map-Format contains a description of the format.
            XmlDocument Doc = new XmlDocument();
            Doc.Load(FilePath);
            if(Doc.GetElementsByTagName("map").Count != 1)
                throw new FormatException("Expected a single map to be defined in a .tmx file.");
            var MapElement = Doc.GetElementsByTagName("map").Item(0);
            var MapDetails = new MapDetails(MapElement);
            List<TextureDetails> Textures = ParseTilesets(MapDetails);
            List<Layer> Layers = ParseLayers(MapDetails, Textures);
            List<Entity> Entities = ParseEntities(MapDetails);
            List<LevelProperty> Properties = ParseProperties(MapDetails);

            LevelData Result = new LevelData() {
                DynamicObjects = Entities.ToArray(),
                Layers = Layers.ToArray(),
                MapSize = new Vector2(MapDetails.MapWidth, MapDetails.MapHeight),
                TileSize = new Vector2(MapDetails.MapTileWidth, MapDetails.MapTileHeight),
                Properties = Properties.ToArray()
            };
            return Result;
        }