Example #1
0
        private DungeonData(TiledMap map, string name)
        {
            this.map    = map;
            Name        = name;
            WidthTiles  = map.Width;
            HeightTiles = map.Height;
            Width       = WidthTiles / Global.RoomWidth;
            Height      = HeightTiles / Global.RoomHeight;
            Tileset     = new Tileset("gfx/game/" + map.Properties.GetString("tileset"), Global.TileSize, Global.TileSize);

            tiles = new DungeonTile[WidthTiles, HeightTiles];

            var layer = map.GetLayer <TiledMapTileLayer>("main");

            for (var ix = 0; ix < WidthTiles; ix++)
            {
                for (var iy = 0; iy < HeightTiles; iy++)
                {
                    var tid = -1;
                    if (layer.TryGetTile(ix, iy, out TiledMapTile? tiledTile))
                    {
                        tid = tiledTile.Value.GlobalIdentifier;
                    }

                    var properties = map.GetTilePropertiesAt(layer, ix, iy);
                    var tile       = new DungeonTile(ix, iy, tid, properties);
                    if (properties != null)
                    {
                        InitTile(tile, properties);
                    }
                    tiles[ix, iy] = tile;
                }
            }

            if (PlayerStartTile == null)
            {
                throw new Exception("Dungeon " + this + " has no starting player tile.");
            }

            Log.Debug("Created " + this + " of size " + Width + "x" + Height + " with player start tile " + PlayerStartTile + ".");
        }