/* The TileMap class has two constructors. The first one takes tilesets and map layers, and sets them all correctly. */ public TileMap(List <Tileset> tilesets, AnimatedTileset animatedTileset, List <InterfaceLayer> mapLayers, AnimatedMapLayer animatedLayer) { this.tilesets = tilesets; this.mapLayers = mapLayers; this.animatedTileset = animatedTileset; this.animatedLayer = animatedLayer; }
/* The second constructor only takes one map layer instead of a list of them. * It does the same as the first constructor, except the mapLayers list is initialized, and the first layer is added from there. */ public TileMap(Tileset tileset, AnimatedTileset animatedTileset, MapLayer layer) { tilesets = new List <Tileset>(); tilesets.Add(tileset); this.animatedTileset = animatedTileset; animatedLayer = new AnimatedMapLayer(); mapLayers = new List <InterfaceLayer>(); mapLayers.Add(layer); }
/* The Draw() function takes an AnimatedTileset as a parameter and uses it to draw each tile in the list. */ public void Draw(SpriteBatch spriteBatch, AnimatedTileset tileset) { /* First, the destination Rectangle is initialized with no position and the height and width of a tile. */ Rectangle dest = new Rectangle(0, 0, Engine.TileWidth, Engine.TileHeight); foreach (Point p in animatedTiles.Keys) { /* For each tile in the list, the destination is set to the tile coordinates multiplied by the tile width/height. */ dest.X = p.X * Engine.TileWidth; dest.Y = p.Y * Engine.TileHeight; /* Finally, the image is drawn using the source frame from the AnimatedTileset, and no colour tint. */ spriteBatch.Draw(tileset.Image, dest, tileset.SourceFrames[animatedTiles[p].TileIndex][animatedTiles[p].CurrentFrame], Color.White); } }