Suppose you are making a strategy game, and an attack hits all tiles in a cross pattern. This attack is used on the tile at row 2, column 3. You want to check each tile that was affected to see if any unit was hit:
1 // cross pattern 2 ubyte[][] attackPattern = [ 3 [0,1,0] 4 [1,1,1] 5 [0,1,0] 6 ]; 7 8 // get tiles contained by a cross pattern centered at (2,3) 9 auto tilesHit = map.maskTilesAround((RowCol(2, 3), attackPattern)); 10 11 // now do something with those tiles 12 auto unitsHit = tilesHit.map!(tile => tile.unitOnTile).filter!(unit => unit !is null); 13 foreach(unit ; unitsHit) unit.applySomeEffect;
Select specific tiles from this slice based on a mask.
The upper left corner of the mask is positioned at the given offset. Each map tile that is overlaid with a 'true' value is included in the result. The mask is allowed to extend out of bounds - out of bounds coordinates are ignored