Midnight Blue Game and Engine
Public Member Functions | Properties | List of all members
MB2D.Collision.CollisionMap Class Reference

A 2D Grid that represents a particular space in the game world to check for collisions. Uses spatial indexing to determine where an entity will be located at any given time. For best results, the cellsize and overall size of the map should be tweaked for each individual game screen and environment. More...

Collaboration diagram for MB2D.Collision.CollisionMap:
Collaboration graph

Public Member Functions

 CollisionMap (int xMin, int xMax, int yMin, int yMax, int cellSize)
 Initializes a new instance of the T:MB2D.Collision.CollisionMap class. More...
 
Point IndexOf (Point position)
 Indexes a world-based coordinate into the collision grid More...
 
bool IndexExists (int x, int y)
 Checks if a particular index exists in the grid More...
 
bool IndexExists (Point index)
 Checks if a particular index exists in the grid More...
 
void Insert (Entity entity, CollisionComponent collision)
 Inserts an entity and its associated collision component into the grid More...
 
List< EntityGetCollisions (Entity entity, CollisionComponent collision)
 Gets a list of all entities located in the same cell/s as a specific single entity More...
 
void UpdatePosition (int x, int y)
 Updates the position of the collision grid. More...
 
void Clear ()
 Clears all non-empty cells of the grid from their entities More...
 

Properties

Grid Grid [get]
 Gets the geometric representation of the grid More...
 
Vector2 Position [get]
 Gets the current position of the grid. More...
 
Vector2 Max [get]
 Gets the upper bounds of the x and y coordinates in the grid More...
 

Detailed Description

A 2D Grid that represents a particular space in the game world to check for collisions. Uses spatial indexing to determine where an entity will be located at any given time. For best results, the cellsize and overall size of the map should be tweaked for each individual game screen and environment.

Constructor & Destructor Documentation

§ CollisionMap()

MB2D.Collision.CollisionMap.CollisionMap ( int  xMin,
int  xMax,
int  yMin,
int  yMax,
int  cellSize 
)
inline

Initializes a new instance of the T:MB2D.Collision.CollisionMap class.

Parameters
xMinThe grids left most x coordinate.
xMaxRight most x coordinae.
yMinTop most y coordinate.
yMaxBottom most y coordinate.
cellSizeThe size of each cell in the grid.

Member Function Documentation

§ Clear()

void MB2D.Collision.CollisionMap.Clear ( )
inline

Clears all non-empty cells of the grid from their entities

Here is the caller graph for this function:

§ GetCollisions()

List<Entity> MB2D.Collision.CollisionMap.GetCollisions ( Entity  entity,
CollisionComponent  collision 
)
inline

Gets a list of all entities located in the same cell/s as a specific single entity

Returns
The entities neighbours.
Parameters
entityEntity to get collisions for.
collisionCollision component to use in checking.
Here is the caller graph for this function:

§ IndexExists() [1/2]

bool MB2D.Collision.CollisionMap.IndexExists ( int  x,
int  y 
)
inline

Checks if a particular index exists in the grid

Returns
true, if index exists, false otherwise.
Parameters
xThe x coordinate.
yThe y coordinate.

§ IndexExists() [2/2]

bool MB2D.Collision.CollisionMap.IndexExists ( Point  index)
inline

Checks if a particular index exists in the grid

Returns
true, if index exists, false otherwise.
Parameters
indexIndex to check.

§ IndexOf()

Point MB2D.Collision.CollisionMap.IndexOf ( Point  position)
inline

Indexes a world-based coordinate into the collision grid

Returns
The grid-based position.
Parameters
positionWorld-based position to index.

§ Insert()

void MB2D.Collision.CollisionMap.Insert ( Entity  entity,
CollisionComponent  collision 
)
inline

Inserts an entity and its associated collision component into the grid

Parameters
entityEntity to insert.
collisionThe entities collision component.
Here is the call graph for this function:
Here is the caller graph for this function:

§ UpdatePosition()

void MB2D.Collision.CollisionMap.UpdatePosition ( int  x,
int  y 
)
inline

Updates the position of the collision grid.

Parameters
xThe x coordinate.
yThe y coordinate.

Property Documentation

§ Grid

Grid MB2D.Collision.CollisionMap.Grid
get

Gets the geometric representation of the grid

The grid.

§ Max

Vector2 MB2D.Collision.CollisionMap.Max
get

Gets the upper bounds of the x and y coordinates in the grid

The max coordinates.

§ Position

Vector2 MB2D.Collision.CollisionMap.Position
get

Gets the current position of the grid.

The position.


The documentation for this class was generated from the following file: