![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A square map. More...
#include <gf/Map.h>
Public Member Functions | |
SquareMap (Vector2i size) | |
Constructor. More... | |
Vector2i | getSize () const |
Get the size of the map. More... | |
PositionRange< int > | getRange () const |
Get a range of the positions of the map. More... | |
Cell properties | |
void | setCell (Vector2i pos, Flags< CellProperty > flags) |
Set the properties of a cell. More... | |
void | reset (Flags< CellProperty > flags) |
Initialize the cells with some properties. More... | |
void | setTransparent (Vector2i pos, bool transparent=true) |
Make a cell transparent. More... | |
bool | isTransparent (Vector2i pos) const |
Check if a cell is transparent. More... | |
void | setWalkable (Vector2i pos, bool walkable=true) |
Make a cell walkable. More... | |
bool | isWalkable (Vector2i pos) const |
Check if a cell is walkable. More... | |
void | setEmpty (Vector2i pos) |
Make a cell empty. More... | |
Field of Vision | |
void | clearFieldOfVision () |
Make the whole map not visible. More... | |
void | clearExplored () |
Make the whole map not explored. More... | |
void | computeFieldOfVision (Vector2i pos, int maxRadius=0, FieldOfVisionLimit limit=FieldOfVisionLimit::Included, FieldOfVision algorithm=FieldOfVision::Basic) |
Compute a field of vision. More... | |
void | computeLocalFieldOfVision (Vector2i pos, int maxRadius=0, FieldOfVisionLimit limit=FieldOfVisionLimit::Included, FieldOfVision algorithm=FieldOfVision::Basic) |
Compute a local field of vision. More... | |
bool | isInFieldOfVision (Vector2i pos) const |
Check if a cell is visible. More... | |
bool | isExplored (Vector2i pos) const |
Check if a cell is explored. More... | |
Route | |
std::vector< Vector2i > | computeRoute (Vector2i origin, Vector2i target, float diagonalCost=Sqrt2, Route algorithm=Route::AStar) |
Compute a route between two points. More... | |
A square map.
A square map is a model of map where cells are organized in a square grid. This type of map is quite common in games. gf provides some useful algorithms related to square maps: field of vision, route finding.
A cell can be transparent and/or walkable. By default, all cells are neither transparent nor walkable i.e. they are walls. The transparent property of a cell is used to compute the field of vision. The walkable property of a cell is used to compute routes. A cell can be transparent and not walkable (e.g. lava or water), it can be walkable and not transparent (e.g. a secret passage).
gf::SquareMap::SquareMap | ( | Vector2i | size | ) |
Constructor.
size | The size of the map |
void gf::SquareMap::clearExplored | ( | ) |
Make the whole map not explored.
You should call this function before exploring a new map.
void gf::SquareMap::clearFieldOfVision | ( | ) |
Make the whole map not visible.
You should call this function before computing a new field of vision.
void gf::SquareMap::computeFieldOfVision | ( | Vector2i | pos, |
int | maxRadius = 0 , |
||
FieldOfVisionLimit | limit = FieldOfVisionLimit::Included , |
||
FieldOfVision | algorithm = FieldOfVision::Basic |
||
) |
Compute a field of vision.
The map is not cleared before computing the field of vision. The algorithm use the transparent property of the cells. After calling this function, some cells are marked visible.
This algorithm marks visible cells as explored.
pos | The position of the entity |
maxRadius | The maximum radius that the entity can see |
limit | Is the limit included in the field of vision? |
algorithm | The algorithm to use for computing the field of vision |
void gf::SquareMap::computeLocalFieldOfVision | ( | Vector2i | pos, |
int | maxRadius = 0 , |
||
FieldOfVisionLimit | limit = FieldOfVisionLimit::Included , |
||
FieldOfVision | algorithm = FieldOfVision::Basic |
||
) |
Compute a local field of vision.
The map is not cleared before computing the field of vision. The algorithm use the transparent property of the cells. After calling this function, some cells are marked visible.
This algorithm does not mark visible cells as explored. It can be used for computing an ennemy field of view without modifying the explored area of the hero.
pos | The position of the entity |
maxRadius | The maximum radius that the entity can see |
limit | Is the limit included in the field of vision? |
algorithm | The algorithm to use for computing the field of vision |
std::vector< Vector2i > gf::SquareMap::computeRoute | ( | Vector2i | origin, |
Vector2i | target, | ||
float | diagonalCost = Sqrt2 , |
||
Route | algorithm = Route::AStar |
||
) |
Compute a route between two points.
The algorithm use the walkable property of the cells. Diagonal movement can be allowed and its cost can be adjusted (defaults to \( \sqrt{2} \)).
origin | The origin of the route |
target | The target of the route |
diagonalCost | The cost of going diagonal between two cells (0 means no diagonal movement) |
algorithm | The algorithm to use for computing the route |
PositionRange< int > gf::SquareMap::getRange | ( | ) | const |
Get a range of the positions of the map.
Vector2i gf::SquareMap::getSize | ( | ) | const |
Get the size of the map.
bool gf::SquareMap::isExplored | ( | Vector2i | pos | ) | const |
Check if a cell is explored.
Cells are explored if they have been in the field of vision after a call to clearExplored().
bool gf::SquareMap::isInFieldOfVision | ( | Vector2i | pos | ) | const |
Check if a cell is visible.
Cells can be made visible by computing a field of vision.
bool gf::SquareMap::isTransparent | ( | Vector2i | pos | ) | const |
bool gf::SquareMap::isWalkable | ( | Vector2i | pos | ) | const |
Check if a cell is walkable.
void gf::SquareMap::reset | ( | Flags< CellProperty > | flags | ) |
Initialize the cells with some properties.
flags | The properties to set |
void gf::SquareMap::setCell | ( | Vector2i | pos, |
Flags< CellProperty > | flags | ||
) |
Set the properties of a cell.
This function directly set all the properties of a cell. You should use the other functions that set a particular property.
pos | The position of the cell |
flags | The properties of the cell |
void gf::SquareMap::setEmpty | ( | Vector2i | pos | ) |
Make a cell empty.
An empty cell is walkable and transparent
pos | The position of the cell |
void gf::SquareMap::setTransparent | ( | Vector2i | pos, |
bool | transparent = true |
||
) |
Make a cell transparent.
pos | The position of the cell |
transparent | The new transparent status of the cell |
void gf::SquareMap::setWalkable | ( | Vector2i | pos, |
bool | walkable = true |
||
) |
Make a cell walkable.
pos | The position of the cell |
walkable | The new walkable status of the cell |