Tile and Cell Selection with RogueSharp
v2 RLNET Tutorials
One of the features of RogueSharp is that it contains multiple methods for selecting Cells in different areas and patterns.
Note: Some people call these Tiles instead of Cells. I believe the terms Cell and Tile are interchangeable but I’ll be using the term Cell for the remainder of this tutorial.
Sample Selection Application
The sample code for the application pictured in the above image is on Bitbucket:
https://bitbucket.org/FaronBracy/roguesharprlnetsamples/branch/AreaSelection
When using the sample the Cell selection will be centered on the mouse cursor.
Commands:
- Left Click – Cycle through selection types
- W Key – Toggle highlighting of walls on and off
- Q Key – Decrease the selection size
- E Key – Increase the selection size
Selection Types
All of the different selection types are methods on the Map class that return an **IEnumerable**. It is then easy to write a foreach loop that will iterate through each of the selected Cells and do something with it. In the example code we just set the background color of the Cell to yellow. There are lots of other applications though. Perhaps you have a wizard in your game that can cast fireballs that explode and damage all enemies in a given radius. This would be perfect for that. |
GetCellsInRadius
GetBorderCellsInRadius
GetCellsInArea
GetBorderCellsInArea
GetCellsInColumns
GetCellsInRows
Toggle Wall Selection
By default all of the selection methods will return every Cell in the area regardless of type. Because the selections all return IEnumerable it means that we can use Linq to filter them. So if we wanted to only select Cells that were walkable we could do something like this.
I hope that this helps clear up how some of the different map selection methods works. Thank you for reading!