Interface IMap
A Map represents a rectangular grid of Cells, each of which has a number of properties for determining walkability, field-of-view and so on The upper left corner of the Map is Cell (0,0) and the X value increases to the right, as the Y value increases downward
Namespace: RogueSharp
Assembly: RogueSharp.dll
Syntax
public interface IMap
Properties
| Improve this Doc View SourceHeight
How many Cells tall the Map is
Declaration
int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
A Map with a Height of 20 will have Cells with Y locations of 0 through 19 Cells with an Y value of 0 will be the topmost Cells
Width
How many Cells wide the Map is
Declaration
int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
A Map with a Width of 10 will have Cells with X locations of 0 through 9 Cells with an X value of 0 will be the leftmost Cells
Methods
| Improve this Doc View SourceAppendFov(Int32, Int32, Int32, Boolean)
Performs a field-of-view calculation with the specified parameters and appends it any existing field-of-view calculations. Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius.
Declaration
ReadOnlyCollection<ICell> AppendFov(int xOrigin, int yOrigin, int radius, bool lightWalls)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xOrigin | X location of the Cell to perform the field-of-view calculation with 0 as the farthest left |
System.Int32 | yOrigin | Y location of the Cell to perform the field-of-view calculation with 0 as the top |
System.Int32 | radius | The number of Cells in which the field-of-view extends from the origin Cell. Think of this as the intensity of the light source. |
System.Boolean | lightWalls | True if walls should be included in the field-of-view when they are within the radius of the light source. False excludes walls even when they are within range. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<ICell> | List of Cells representing what is observable in the Map based on the specified parameters |
Examples
When a character is holding a light source in a large area that also has several other sources of light such as torches along the walls ComputeFov could first be called for the character and then AppendFov could be called for each torch to give us the final combined FOV given all the light sources
| Improve this Doc View SourceCellFor(Int32)
Get the Cell at the specified single dimensional array index using the formulas: x = index % Width; y = index / Width;
Declaration
ICell CellFor(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The single dimensional array index for the Cell that we want to get |
Returns
Type | Description |
---|---|
ICell | Cell at the specified single dimensional array index |
Clear()
Sets the properties of all Cells in the Map to be transparent and walkable
Declaration
void Clear()
Clear(Boolean, Boolean)
Sets the properties of all Cells in the Map to the specified values
Declaration
void Clear(bool isTransparent, bool isWalkable)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isTransparent | Optional parameter defaults to false if not provided. True if line-of-sight is not blocked by this Cell. False otherwise |
System.Boolean | isWalkable | Optional parameter defaults to false if not provided. True if a character could walk across the Cell normally. False otherwise |
Clone<T>()
Create and return a deep copy of an existing Map
Declaration
T Clone<T>()
where T : IMap, new()
Returns
Type | Description |
---|---|
T | T of type IMap which is a deep copy of the original Map |
Type Parameters
Name | Description |
---|---|
T |
ComputeFov(Int32, Int32, Int32, Boolean)
Performs a field-of-view calculation with the specified parameters. Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius. Any existing field-of-view calculations will be overwritten when calling this method.
Declaration
ReadOnlyCollection<ICell> ComputeFov(int xOrigin, int yOrigin, int radius, bool lightWalls)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xOrigin | X location of the Cell to perform the field-of-view calculation with 0 as the farthest left |
System.Int32 | yOrigin | Y location of the Cell to perform the field-of-view calculation with 0 as the top |
System.Int32 | radius | The number of Cells in which the field-of-view extends from the origin Cell. Think of this as the intensity of the light source. |
System.Boolean | lightWalls | True if walls should be included in the field-of-view when they are within the radius of the light source. False excludes walls even when they are within range. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<ICell> | List of Cells representing what is observable in the Map based on the specified parameters |
Copy(IMap)
Copies the Cell properties of a smaller source Map into this destination Map at location (0,0)
Declaration
void Copy(IMap sourceMap)
Parameters
Type | Name | Description |
---|---|---|
IMap | sourceMap | An IMap which must be of smaller size and able to fit in this destination Map at the specified location |
Copy(IMap, Int32, Int32)
Copies the Cell properties of a smaller source Map into this destination Map at the specified location
Declaration
void Copy(IMap sourceMap, int left, int top)
Parameters
Type | Name | Description |
---|---|---|
IMap | sourceMap | An IMap which must be of smaller size and able to fit in this destination Map at the specified location |
System.Int32 | left | Optional parameter defaults to 0 if not provided. X location of the Cell to start copying parameters to, starting with 0 as the farthest left |
System.Int32 | top | Optional parameter defaults to 0 if not provided. Y location of the Cell to start copying parameters to, starting with 0 as the top |
GetAllCells()
Get an IEnumerable of all Cells in the Map
Declaration
IEnumerable<ICell> GetAllCells()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all Cells in the Map |
GetBorderCellsInCircle(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a circle around the center Cell up to the specified radius using Bresenham's midpoint circle algorithm
Declaration
IEnumerable<ICell> GetBorderCellsInCircle(int xCenter, int yCenter, int radius)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | radius | The number of Cells to get in a radius from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a circle around the center Cell |
See Also
| Improve this Doc View SourceGetBorderCellsInDiamond(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a diamond (Rhombus) shape around the center Cell up to the specified distance
Declaration
IEnumerable<ICell> GetBorderCellsInDiamond(int xCenter, int yCenter, int distance)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | distance | The number of Cells to get in a distance from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a diamond (Rhombus) shape around the center Cell |
GetBorderCellsInSquare(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a square area around the center Cell up to the specified distance
Declaration
IEnumerable<ICell> GetBorderCellsInSquare(int xCenter, int yCenter, int distance)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | distance | The number of Cells to get in each direction from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a square area around the center Cell |
GetCell(Int32, Int32)
Get a Cell at the specified location
Declaration
ICell GetCell(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to get starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to get, starting with 0 as the top |
Returns
Type | Description |
---|---|
ICell | Cell at the specified location |
GetCellsAlongLine(Int32, Int32, Int32, Int32)
Get an IEnumerable of Cells in a line from the Origin Cell to the Destination Cell The resulting IEnumerable includes the Origin and Destination Cells Uses Bresenham's line algorithm to determine which Cells are in the closest approximation to a straight line between the two Cells
Declaration
IEnumerable<ICell> GetCellsAlongLine(int xOrigin, int yOrigin, int xDestination, int yDestination)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xOrigin | X location of the Origin Cell at the start of the line with 0 as the farthest left |
System.Int32 | yOrigin | Y location of the Origin Cell at the start of the line with 0 as the top |
System.Int32 | xDestination | X location of the Destination Cell at the end of the line with 0 as the farthest left |
System.Int32 | yDestination | Y location of the Destination Cell at the end of the line with 0 as the top |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a line from the Origin Cell to the Destination Cell which includes the Origin and Destination Cells |
GetCellsInCircle(Int32, Int32, Int32)
Get an IEnumerable of Cells in a circle around the center Cell up to the specified radius using Bresenham's midpoint circle algorithm
Declaration
IEnumerable<ICell> GetCellsInCircle(int xCenter, int yCenter, int radius)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | radius | The number of Cells to get in a radius from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a circle around the center Cell |
See Also
| Improve this Doc View SourceGetCellsInColumns(Int32[])
Get an IEnumerable of all the Cells in the specified column numbers
Declaration
IEnumerable<ICell> GetCellsInColumns(params int[] columnNumbers)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | columnNumbers | Integer array of column numbers with 0 as the farthest left |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all the Cells in the specified column numbers |
GetCellsInDiamond(Int32, Int32, Int32)
Get an IEnumerable of Cells in a diamond (Rhombus) shape around the center Cell up to the specified distance
Declaration
IEnumerable<ICell> GetCellsInDiamond(int xCenter, int yCenter, int distance)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | distance | The number of Cells to get in a distance from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a diamond (Rhombus) shape around the center Cell |
GetCellsInRectangle(Int32, Int32, Int32, Int32)
Get an IEnumerable of Cells in a rectangle area
Declaration
IEnumerable<ICell> GetCellsInRectangle(int top, int left, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | top | The top row of the rectangle |
System.Int32 | left | The left column of the rectangle |
System.Int32 | width | The width of the rectangle |
System.Int32 | height | The height of the rectangle |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a rectangle area |
GetCellsInRows(Int32[])
Get an IEnumerable of all the Cells in the specified row numbers
Declaration
IEnumerable<ICell> GetCellsInRows(params int[] rowNumbers)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | rowNumbers | Integer array of row numbers with 0 as the top |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all the Cells in the specified row numbers |
GetCellsInSquare(Int32, Int32, Int32)
Get an IEnumerable of Cells in a square area around the center Cell up to the specified distance
Declaration
IEnumerable<ICell> GetCellsInSquare(int xCenter, int yCenter, int distance)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
System.Int32 | distance | The number of Cells to get in each direction from the center Cell |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a square area around the center Cell |
IndexFor(ICell)
Get the single dimensional array index for the specified Cell
Declaration
int IndexFor(ICell cell)
Parameters
Type | Name | Description |
---|---|---|
ICell | cell | The Cell to get the index for |
Returns
Type | Description |
---|---|
System.Int32 | An index for the Cell which is useful if storing Cells in a single dimensional array |
IndexFor(Int32, Int32)
Get the single dimensional array index for a Cell at the specified location using the formula: index = ( y * Width ) + x
Declaration
int IndexFor(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell index to get starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell index to get, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Int32 | An index for the Cell at the specified location useful if storing Cells in a single dimensional array |
Initialize(Int32, Int32)
Create a new map with the properties of all Cells set to false
Declaration
void Initialize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | How many Cells wide the Map will be |
System.Int32 | height | How many Cells tall the Map will be |
Remarks
This is basically a solid stone map that would then need to be modified to have interesting features
IsExplored(Int32, Int32)
Check if the Cell is flagged as ever having been explored by the player
Declaration
bool IsExplored(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Boolean | True if the Cell has been flagged as being explored by the player, false otherwise |
Remarks
The explored property of a Cell can be used to track if the Cell has ever been in the field-of-view of a character controlled by the player This property will not automatically be updated based on FOV calculations or any other built-in functions of the RogueSharp library.
Examples
As the player moves characters around a Map, Cells will enter and exit the currently computed field-of-view This property can be used to keep track of those Cells that have been "seen" and could be used to show fog-of-war type effects when rendering the map
| Improve this Doc View SourceIsInFov(Int32, Int32)
Check if the Cell is in the currently computed field-of-view For newly initialized maps a field-of-view will not exist so all Cells will return false Field-of-view must first be calculated by calling ComputeFov and/or AppendFov
Declaration
bool IsInFov(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Boolean | True if the Cell is in the currently computed field-of-view, false otherwise |
Remarks
Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius
Examples
Field-of-view c be used to simulate a character holding a light source and exploring a Map representing a dark cavern Any Cells within the FOV would be what the character could see from their current location and lighting conditions
| Improve this Doc View SourceIsTransparent(Int32, Int32)
Get the transparency of the Cell i.e. if line of sight would be blocked by this Cell
Declaration
bool IsTransparent(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Boolean | True if line-of-sight is not blocked by this Cell, false otherwise |
Examples
A Cell representing an empty stone floor would be transparent A Cell representing a glass wall could be transparent (even though it may not be walkable) A Cell representing a solid stone wall would not be transparent
| Improve this Doc View SourceIsWalkable(Int32, Int32)
Get the walkability of the Cell i.e. if a character could normally move across the Cell without difficulty
Declaration
bool IsWalkable(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Boolean | True if a character could move across this Cell, false otherwise |
Examples
A Cell representing an empty stone floor would be walkable A Cell representing a glass wall may not be walkable (even though it could be transparent) A Cell representing a solid stone wall would not be walkable
| Improve this Doc View SourceRestore(MapState)
Restore the state of this Map from the specified MapState
Declaration
void Restore(MapState state)
Parameters
Type | Name | Description |
---|---|---|
MapState | state | MapState POCO (Plain Old C# Object) which represents this Map and can be easily serialized and deserialized |
Save()
Get a MapState POCO which represents this Map and can be easily serialized Use Restore with the MapState to get back a full Map
Declaration
MapState Save()
Returns
Type | Description |
---|---|
MapState | MapState POCO (Plain Old C# Object) which represents this Map and can be easily serialized |
SetCellProperties(Int32, Int32, Boolean, Boolean)
Set the properties of an unexplored Cell to the specified values
Declaration
void SetCellProperties(int x, int y, bool isTransparent, bool isWalkable)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to set properties on, starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to set properties on, starting with 0 as the top |
System.Boolean | isTransparent | True if line-of-sight is not blocked by this Cell. False otherwise |
System.Boolean | isWalkable | True if a character could walk across the Cell normally. False otherwise |
Remarks
IsInFov cannot be set through this method as it is always calculated by calling ComputeFov and/or AppendFov
SetCellProperties(Int32, Int32, Boolean, Boolean, Boolean)
Set the properties of a Cell to the specified values
Declaration
void SetCellProperties(int x, int y, bool isTransparent, bool isWalkable, bool isExplored)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Cell to set properties on, starting with 0 as the farthest left |
System.Int32 | y | Y location of the Cell to set properties on, starting with 0 as the top |
System.Boolean | isTransparent | True if line-of-sight is not blocked by this Cell. False otherwise |
System.Boolean | isWalkable | True if a character could walk across the Cell normally. False otherwise |
System.Boolean | isExplored | Optional parameter defaults to false if not provided. True if the Cell has ever been in the field-of-view of the player. False otherwise |
Remarks
IsInFov cannot be set through this method as it is always calculated by calling ComputeFov and/or AppendFov
ToString(Boolean)
Provides a simple visual representation of the map using the following symbols:
%
:Cell
is not in field-of-view.
:Cell
is transparent, walkable, and in field-of-views
:Cell
is walkable and in field-of-view (but not transparent)o
:Cell
is transparent and in field-of-view (but not walkable)#
:Cell
is in field-of-view (but not transparent or walkable)
Declaration
string ToString(bool useFov)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | useFov | True if field-of-view calculations will be used when creating the string representation of the Map. False otherwise |
Returns
Type | Description |
---|---|
System.String | A string representation of the map using special symbols to denote Cell properties |