Dragonfly 4.19
A text-based game engine
Public Member Functions | Private Attributes | List of all members
df::Grid Class Reference

Public Member Functions

void setDimensions (int new_width, int new_height)
 
int getHeight () const
 
int getWidth () const
 
int insertObject (Object *p_o)
 
int removeObject (Object *p_o)
 
Cell positionToCell (Vector where) const
 
std::vector< Cell > positionToCells (Object *p_o, Vector where) const
 
ObjectList getCollisions (Object *p_o, Vector where) const
 
int updatePosition (Object *p_o, Vector where)
 
ObjectList getObjects (Cell cell) const
 
std::string toString () const
 
void print () const
 
int startUp ()
 
void shutDown ()
 

Private Attributes

ObjectList ** m_p_grid
 
ObjectList m_out_of_bounds
 
int m_width
 
int m_height
 

Member Function Documentation

◆ getCollisions()

ObjectList df::Grid::getCollisions ( Object p_o,
Vector  where 
) const

Return all Objects that collide at given location.

List is empty if none.

◆ getHeight()

int df::Grid::getHeight ( ) const

Get height.

◆ getObjects()

ObjectList df::Grid::getObjects ( Cell  cell) const

Get Objects in a given Cell.

◆ getWidth()

int df::Grid::getWidth ( ) const

Get width.

◆ insertObject()

int df::Grid::insertObject ( Object p_o)

Insert Object into grid.

Return 0 if ok, else -1.

◆ positionToCell()

Cell df::Grid::positionToCell ( Vector  where) const

Return Cell (x,y) for given location.

◆ positionToCells()

std::vector< Cell > df::Grid::positionToCells ( Object p_o,
Vector  where 
) const

Return list of Cells for given Object at given location.

Out of bounds cell is (-1, -1).

◆ print()

void df::Grid::print ( ) const

Write grid to logfile.

◆ removeObject()

int df::Grid::removeObject ( Object p_o)

Remove Object from grid.

Return 0 if ok, else -1.

◆ setDimensions()

void df::Grid::setDimensions ( int  new_width,
int  new_height 
)

Set dimensions. Deletes and re-creates grid.

◆ shutDown()

void df::Grid::shutDown ( )

Shutdown (delete grid).

◆ toString()

std::string df::Grid::toString ( ) const

Return grid as string.

◆ updatePosition()

int df::Grid::updatePosition ( Object p_o,
Vector  where 
)

Move Object from old position, add to new position.

Return 0 if ok, else -1.

Member Data Documentation

◆ m_height

int df::Grid::m_height
private

Grid height.

◆ m_out_of_bounds

ObjectList df::Grid::m_out_of_bounds
private

All out of bounds objects.

◆ m_p_grid

ObjectList** df::Grid::m_p_grid
private

The grid.

◆ m_width

int df::Grid::m_width
private

Grid width.