Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::SquareMap Class Reference

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, CellFlags flags)
 Set the properties of a cell. More...
 
void reset (CellFlags flags)
 Initialize the cells with some properties. More...
 
void setTransparent (Vector2i pos)
 Make a cell transparent. More...
 
bool isTransparent (Vector2i pos) const
 Check if a cell is transparent. More...
 
void setWalkable (Vector2i pos)
 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< Vector2icomputeRoute (Vector2i origin, Vector2i target, float diagonalCost=Sqrt2, Route algorithm=Route::AStar)
 Compute a route between two points. More...
 

Detailed Description

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).

See also
gf::CellProperty

Constructor & Destructor Documentation

◆ SquareMap()

gf::SquareMap::SquareMap ( Vector2i  size)

Constructor.

Parameters
sizeThe size of the map

Member Function Documentation

◆ clearExplored()

void gf::SquareMap::clearExplored ( )

Make the whole map not explored.

You should call this function before exploring a new map.

See also
computeFieldOfVision()

◆ clearFieldOfVision()

void gf::SquareMap::clearFieldOfVision ( )

Make the whole map not visible.

You should call this function before computing a new field of vision.

See also
computeFieldOfVision()

◆ computeFieldOfVision()

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.

Parameters
posThe position of the entity
maxRadiusThe maximum radius that the entity can see
limitIs the limit included in the field of vision?
algorithmThe algorithm to use for computing the field of vision
See also
clearFieldOfVision(), isInFieldOfVision()

◆ computeLocalFieldOfVision()

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.

Parameters
posThe position of the entity
maxRadiusThe maximum radius that the entity can see
limitIs the limit included in the field of vision?
algorithmThe algorithm to use for computing the field of vision
See also
clearFieldOfVision(), isInFieldOfVision()

◆ computeRoute()

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} \)).

Parameters
originThe origin of the route
targetThe target of the route
diagonalCostThe cost of going diagonal between two cells (0 means no diagonal movement)
algorithmThe algorithm to use for computing the route
Returns
The route between the two points (included)

◆ getRange()

PositionRange<int> gf::SquareMap::getRange ( ) const

Get a range of the positions of the map.

Returns
A 2D range of all the positions
See also
Array2D::getPositionRange()

◆ getSize()

Vector2i gf::SquareMap::getSize ( ) const

Get the size of the map.

Returns
The size of the map

◆ isExplored()

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().

See also
computeFieldOfVision(), isInFieldOfVision()

◆ isInFieldOfVision()

bool gf::SquareMap::isInFieldOfVision ( Vector2i  pos) const

Check if a cell is visible.

Cells can be made visible by computing a field of vision.

Returns
True if the cell is visible
See also
computeFieldOfVision()

◆ isTransparent()

bool gf::SquareMap::isTransparent ( Vector2i  pos) const

Check if a cell is transparent.

Returns
True if the cell is transparent
See also
setTransparent()

◆ isWalkable()

bool gf::SquareMap::isWalkable ( Vector2i  pos) const

Check if a cell is walkable.

See also
setWalkable()

◆ reset()

void gf::SquareMap::reset ( CellFlags  flags)

Initialize the cells with some properties.

Parameters
flagsThe properties to set

◆ setCell()

void gf::SquareMap::setCell ( Vector2i  pos,
CellFlags  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.

Parameters
posThe position of the cell
flagsThe properties of the cell
See also
setTransparent(), setWalkable(), setEmpty()

◆ setEmpty()

void gf::SquareMap::setEmpty ( Vector2i  pos)

Make a cell empty.

An empty cell is walkable and transparent

Parameters
posThe position of the cell

◆ setTransparent()

void gf::SquareMap::setTransparent ( Vector2i  pos)

Make a cell transparent.

Parameters
posThe position of the cell
See also
isTransparent()

◆ setWalkable()

void gf::SquareMap::setWalkable ( Vector2i  pos)

Make a cell walkable.

Parameters
posThe position of the cell
See also
isWalkable()