FYP  1.0.0
Final Year Project -- Alexander Meuer
TowerPlacer Class Reference
Collaboration diagram for TowerPlacer:
Collaboration graph

Public Types

enum  TowerType { ARROW, MAGIC, UNIT }
 

Public Member Functions

 TowerPlacer (shared_ptr< TerrainTree > const &terrainTree, shared_ptr< ProjectileManager > const &projectileMgr, shared_ptr< Path > const &path, std::function< void(shared_ptr< Minion >)> const &unitSpawnCallback)
 Constructs an instance of TowerPlacer. More...
 
shared_ptr< tower::Towerplace ()
 If location is valid for tower placement, puts a tower into the container.
 
virtual void update (sf::Vector2f const &mousePosition)
 Updates position to match mouse and calculates validity.
 
void activate (TowerType type)
 Sets the TowerPlacer to be active. Must be called before update, draw or place do anything. More...
 
void setSticky (bool sticky)
 If true, placing a tower will not remove the tower placer form the cursor.
 
void draw (sf::RenderTarget &renderTarget) const
 Draws the tower overlay to the render target. More...
 
bool isActive () const
 

Protected Member Functions

virtual void checkValidity ()
 Checks if the current location is valid for placement.
 
void calculateColor ()
 Sets the color of the overlay to red or green depending on validity.
 

Protected Attributes

TowerType mTowerType
 The type of tower that will be placed.
 
bool mIsActive
 If this is false, calls to methods other than activate() will do nothing.
 
bool mIsValid
 True if the current location is valid for tower placement.
 
shared_ptr< TerrainTreemTerrainTree
 The Quadtree<unsigned char> that will be used to check points against terrain for validity.
 
sf::Sprite mOverlay
 A ghost tower that show where the tower would be placed and colored to show validity.
 
sf::Shape * mMask
 Shape used to test for validity with the terrain tree.
 
bool mIsSticky
 If true, placing a tower will not deactivate the placer.
 

Private Attributes

collision::CollisionGroup mTowerCollisionGroup
 Used to prevent the player from placing towers on top of each other.
 
const shared_ptr< ProjectileManagermProjectileManager
 
const shared_ptr< PathmPath
 
const std::function< void(shared_ptr< Minion >)> mUnitSpawnCallback
 

Static Private Attributes

static const sf::Color mValidColor
 
static const sf::Color mInvalidColor
 
static const std::string mArrowTowerDefPath
 
static const std::string mMagicTowerDefPath
 
static const std::string mUnitTowerDefPath
 

Constructor & Destructor Documentation

TowerPlacer::TowerPlacer ( shared_ptr< TerrainTree > const &  terrainTree,
shared_ptr< ProjectileManager > const &  projectileMgr,
shared_ptr< Path > const &  path,
std::function< void(shared_ptr< Minion >)> const &  unitSpawnCallback 
)

Constructs an instance of TowerPlacer.

Parameters
terrainTreeQuadtree used to determine where is valid for tower placement.
projectileMgrShared pointer to a ProjectileManager. Created towers will add their projectiles to this.
pathPath onto which UnitTowers will send their spawned units.
unitSpawnCallbackGiven to unit towers so that they can spawn units.

Member Function Documentation

void TowerPlacer::activate ( TowerType  type)

Sets the TowerPlacer to be active. Must be called before update, draw or place do anything.

Parameters
typeThe type of tower to be placed.
void TowerPlacer::draw ( sf::RenderTarget &  renderTarget) const

Draws the tower overlay to the render target.

Remarks
If debugging, also draws the collision mask.

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