Rasterization-DiscoBall
 All Classes Files Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
MapElement Class Reference

Parent class for elements in the map. More...

#include <Map.h>

Inheritance diagram for MapElement:
Bullet Creature Cube Archer Bomber Crawler Creeper SmartCrawler SuperCrawler BasicTower

Public Member Functions

bool atDiscoBall (int x, int y, int z, int range)
 Helper for calling atDiscoBall(IntVec3 v, int range) More...
 
bool atDiscoBall (IntVec3 v, int range)
 
bool attack (int x, int y, int z, int damage)
 Attack the position on a grid Does attack damage if a Creature and defend Damage if a Cube. More...
 
bool attack (IntVec3 v, int damage)
 Helper for calling attack(int x,int y,int z,int damage) More...
 
bool attack (IntVec3 old, int x, int y, int z, int damage)
 Helper for calling attack(int x,int y,int z,int damage) More...
 
bool attackDiscoBall (int damage)
 Attack the Disco Ball!!!! More...
 
bool boundaryCheck (int x, int y, int z)
 Check if this position is in the Map grid in order to avoid bad access. More...
 
virtual AABox getAABox ()
 Get the AABox corresponding to the creature. More...
 
virtual int getBounty ()
 
virtual int getOccupancy ()
 
virtual int getType ()
 
bool hasBox (int x, int y, int z)
 Check if there is a box at the specified position. More...
 
bool hasBox (IntVec3 v)
 Helper for calling hasBox(int x, int y, int z);. More...
 
bool inMap ()
 Check if the MapElement is close to the Disco Ball. More...
 
bool isValidMove (int x, int y, int z)
 Check if can move to the position Can move if the occupancy of this MapElement sums the gridOccupancy of the destination grid is less than or equal to 100. More...
 
bool isValidMove (IntVec3 v)
 Helper for calling isValidMove(int x, int y, int z);. More...
 
bool isValidMove (IntVec3 old, int x, int y, int z)
 Helper for calling isValidMove(int x, int y, int z);. More...
 
 MapElement (shared_ptr< VisibleEntity > e, int x, int y, int z, Map *m)
 Constructor. More...
 
virtual bool move ()
 Take a move This is the method that actually determines the behavior of the creature. More...
 
virtual void onDeath ()
 Update m_map when it dies. More...
 
virtual void onSpawn ()
 Update m_map when it spawns. More...
 
bool operator< (const MapElement &other) const
 Overloaded less than for sorting. More...
 
float randFloat ()
 Generates pseudo-random float between 0 and 1. More...
 
virtual void run ()
 Called every frame to update the MapElement A MapElement takes a certain number of turns(frames) to finish a move. More...
 
virtual void takeDamage ()
 Takes damage from the grid for both the oldPos and newPos. More...
 
void updateHP ()
 Called every frame to update the HP of the MapElement. More...
 

Public Attributes

AABox aaBox
 Used for raycasting. More...
 
bool change
 True if anything about it has changed in the past frame, vice versa. More...
 
Vector3 displacement
 Displacement per frame. More...
 
shared_ptr< VisibleEntity > entity
 Pointer to the VisibleEntity in the actual Scene. More...
 
Mapm_map
 Pointer to the map. More...
 
int maxHP
 Max HP of creature. More...
 
int newHP
 HP at this frame. More...
 
Vector3 newOffset
 Offset used for random placement within a Map grid. More...
 
IntVec3 newPos
 Destination of this after finishing the current move. More...
 
int oldHP
 HP before this frame. More...
 
Vector3 oldOffset
 Offset used for random placement within a Map grid. More...
 
IntVec3 oldPos
 Previous position of this before the current move. More...
 
int suicide = false
 If true, no bounty is given upon death. More...
 
int turnsLeft
 Number of frames left before the current move is finished. More...
 

Detailed Description

Parent class for elements in the map.

Only child classes should be used A MapElement is the basic unit in Map. It contains information about is location, HP and etc, as well as methods that provides basic attack and move methods. In addition to that, it also contains information about its graphical representation.

Extended by Creature and Cube

Constructor & Destructor Documentation

MapElement::MapElement ( shared_ptr< VisibleEntity >  e,
int  x,
int  y,
int  z,
Map m 
)

Constructor.

Parameters
eentity
x,y,zused for initializating oldPos and newPos
mm_map

Member Function Documentation

bool MapElement::atDiscoBall ( int  x,
int  y,
int  z,
int  range 
)

Helper for calling atDiscoBall(IntVec3 v, int range)

Parameters
x,y,zposition of MapElement
rangerange of attack, in mahattan distance
bool MapElement::atDiscoBall ( IntVec3  v,
int  range 
)
bool MapElement::attack ( int  x,
int  y,
int  z,
int  damage 
)

Attack the position on a grid Does attack damage if a Creature and defend Damage if a Cube.

The damage is distributed to corresponding MapElement in the grid with weight base on corresponding occupancy.

Parameters
x,y,zgrid to attack
damageDamage dealt

See Map::attackDamage and Map::defendDamage for more info.

bool MapElement::attack ( IntVec3  v,
int  damage 
)

Helper for calling attack(int x,int y,int z,int damage)

Parameters
vIntVec3 that contains x,y,z
damageDamage dealt
bool MapElement::attack ( IntVec3  old,
int  x,
int  y,
int  z,
int  damage 
)

Helper for calling attack(int x,int y,int z,int damage)

Parameters
oldIntVec3 that contains the coordinate
x,y,zoffset to IntVec3 old
damageDamage dealt
bool MapElement::attackDiscoBall ( int  damage)

Attack the Disco Ball!!!!

Parameters
damageDamage to Disco Ball
bool MapElement::boundaryCheck ( int  x,
int  y,
int  z 
)

Check if this position is in the Map grid in order to avoid bad access.

Parameters
x,y,zpoint to be checked
AABox MapElement::getAABox ( )
virtual

Get the AABox corresponding to the creature.

Has to be virtual because size vary

int MapElement::getBounty ( )
virtual
Returns
the bounty of it when killed, applicable to only Creature

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, and Creature.

int MapElement::getOccupancy ( )
virtual
Returns
the occupancy of it

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, Creature, BasicTower, and Cube.

int MapElement::getType ( )
virtual
Returns
the type of it

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, Creature, BasicTower, and Cube.

bool MapElement::hasBox ( int  x,
int  y,
int  z 
)

Check if there is a box at the specified position.

Parameters
x,y,zposition to be checked
bool MapElement::hasBox ( IntVec3  v)

Helper for calling hasBox(int x, int y, int z);.

Parameters
vIntVec3 of the position
bool MapElement::inMap ( )

Check if the MapElement is close to the Disco Ball.

Parameters
vposition of MapElement
rangerange of attack, in mahattan distance

See Map::discoBallLoc for more infoCheck if the MapElement is inside the map. Used for visualizing the creatures approaching the playable map

bool MapElement::isValidMove ( int  x,
int  y,
int  z 
)

Check if can move to the position Can move if the occupancy of this MapElement sums the gridOccupancy of the destination grid is less than or equal to 100.

Parameters
x,y,zposition to be checked
bool MapElement::isValidMove ( IntVec3  v)

Helper for calling isValidMove(int x, int y, int z);.

Parameters
vIntVec3 of the position
bool MapElement::isValidMove ( IntVec3  old,
int  x,
int  y,
int  z 
)

Helper for calling isValidMove(int x, int y, int z);.

Parameters
oldIntVec3 that contains the coordinate
x,y,zoffset to IntVec3 old
bool MapElement::move ( )
virtual

Take a move This is the method that actually determines the behavior of the creature.

Called by run() everytime when turnsLeft = 0;

Must update turnsLeft. Must be overridden in sub classesA

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, Creature, BasicTower, Cube, and Bullet.

void MapElement::onDeath ( )
virtual

Update m_map when it dies.

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, Creature, BasicTower, Cube, and Bullet.

void MapElement::onSpawn ( )
virtual

Update m_map when it spawns.

Reimplemented in SuperCrawler, Bomber, Archer, SmartCrawler, Creeper, Crawler, Creature, BasicTower, and Cube.

bool MapElement::operator< ( const MapElement other) const

Overloaded less than for sorting.

float MapElement::randFloat ( )

Generates pseudo-random float between 0 and 1.

void MapElement::run ( )
virtual

Called every frame to update the MapElement A MapElement takes a certain number of turns(frames) to finish a move.

Run is called to check if the current move has been finished. Everytime run() is called, turnsLeft is decremented by 1. If turnsLeft equals 0, move() is called to perform the next move

Reimplemented in Bullet.

void MapElement::takeDamage ( )
virtual

Takes damage from the grid for both the oldPos and newPos.

Takes attack damage if a Cube and defend damage if a Creature.

See Map::attackDamage and Map::defendDamage for more info.

Reimplemented in Bullet.

void MapElement::updateHP ( )

Called every frame to update the HP of the MapElement.

Member Data Documentation

AABox MapElement::aaBox

Used for raycasting.

bool MapElement::change

True if anything about it has changed in the past frame, vice versa.

Vector3 MapElement::displacement

Displacement per frame.

Calculated as the difference between newPos and oldPos(plus offset) divided by the number of turns need to finish a move

shared_ptr<VisibleEntity> MapElement::entity

Pointer to the VisibleEntity in the actual Scene.

Map* MapElement::m_map

Pointer to the map.

int MapElement::maxHP

Max HP of creature.

int MapElement::newHP

HP at this frame.

Vector3 MapElement::newOffset

Offset used for random placement within a Map grid.

Reflects the offset for newPos

IntVec3 MapElement::newPos

Destination of this after finishing the current move.

See move()

int MapElement::oldHP

HP before this frame.

Vector3 MapElement::oldOffset

Offset used for random placement within a Map grid.

Reflects the offset for oldPos

IntVec3 MapElement::oldPos

Previous position of this before the current move.

int MapElement::suicide = false

If true, no bounty is given upon death.

int MapElement::turnsLeft

Number of frames left before the current move is finished.

See move()


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