internal TiledMapLayerAnimatedModel(ContentReader reader, TiledMap map) : base(reader, true) { var tilesetFirstGlobalIdentifier = reader.ReadInt32(); var tileset = map.GetTilesetByTileGlobalIdentifier(tilesetFirstGlobalIdentifier); var animatedTilesetTileCount = reader.ReadInt32(); AnimatedTilesetTiles = new TiledMapTilesetAnimatedTile[animatedTilesetTileCount]; for (var i = 0; i < animatedTilesetTileCount; i++) { var tileLocalIdentifier = reader.ReadInt32(); AnimatedTilesetTiles[i] = tileset.GetAnimatedTilesetTileByLocalTileIdentifier(tileLocalIdentifier); } }
public GameMap(TiledMap tiledMap) { TiledMap = tiledMap; tiles = new Tile[tiledMap.Width, tiledMap.Height]; foreach (var layer in tiledMap.TileLayers) { for (int x = 0; x < layer.Width; x++) { for (int y = 0; y < layer.Height; y++) { if (tiles[x, y] == null) { tiles[x, y] = new Tile(this, x, y); } layer.TryGetTile(x, y, out TiledMapTile? tiledMapTile); TiledMapTile layerTile = tiledMapTile.Value; if (layerTile.IsBlank) { continue; } TiledMapTileset tileset = TiledMap.GetTilesetByTileGlobalIdentifier(layerTile.GlobalIdentifier); TiledMapTilesetTile tilesetTile = tileset.Tiles.FirstOrDefault( t => t.LocalTileIdentifier == layerTile.GlobalIdentifier - tileset.FirstGlobalIdentifier); if (tilesetTile != null) { tilesetTile.Properties.TryGetValue("IsWalkable", out string isWalkable); tilesetTile.Properties.TryGetValue("IsPlaceable", out string isPlaceable); tilesetTile.Properties.TryGetValue("IsSpawnable", out string isSpawnable); tiles[x, y].IsWalkable = isWalkable == "true"; tiles[x, y].IsPlaceable = isPlaceable == "true"; tiles[x, y].IsSpawnable = isSpawnable == "true"; if (tiles[x, y].IsSpawnable) { spawnableTiles.Add(tiles[x, y]); } } } } } // Store references to each tile's adjacent tiles. foreach (var tile in tiles) { if (tile.Position.X > 0) { tile.AdjacentTiles.Add(this[tile.X - 1, tile.Y]); } if (tile.Position.X < TiledMap.Width - 1) { tile.AdjacentTiles.Add(this[tile.X + 1, tile.Y]); } if (tile.Position.Y > 0) { tile.AdjacentTiles.Add(this[tile.X, tile.Y - 1]); } if (tile.Position.Y < TiledMap.Height - 1) { tile.AdjacentTiles.Add(this[tile.X, tile.Y + 1]); } } }