FYP  1.0.0
Final Year Project -- Alexander Meuer
Hero Class Reference

Pawn that can move and attack simultaneously and regenerates health. More...

#include <Hero.hpp>

Inheritance diagram for Hero:
Inheritance graph
Collaboration diagram for Hero:
Collaboration graph

Public Member Functions

 Hero (tinyxml2::XMLElement *xml)
 
void update (sf::Time const &elapsedTime) override
 Updates the Pawn. State becomes MARCHING is goal is further than attack range. State becomes ATTACKING if has a target and target is within attack range. Else state become IDLE. More...
 
void setDestination (sf::Vector2f const &destination) final override
 Sets the Pawn's destination. More...
 
- Public Member Functions inherited from Pawn
 Pawn (tinyxml2::XMLElement *xml)
 Constructs a pawn from an xml element. Parses members from child xml tags. Requires child <Actor> tag for base class construction. More...
 
void makeSelfAware (std::shared_ptr< Pawn > const &smartThis)
 
sf::Vector2f getDestination () const
 
int getMovementSpeed () const
 
void setMovementSpeed (int newSpeed)
 
void kill ()
 Kills the Pawn outright. Sets the Pawn's health to 0 and the state to DEAD.
 
bool takeDamage (int amount, Damage::Type type)
 
bool takeDamage (int amount, Damage::Type type, std::shared_ptr< Pawn > const &sender)
 Same as takeDamage() Used when taking damage from another pawn, so that we can choose to retaliate if we so wish. More...
 
void heal (int amount)
 Heals for the specified amount. Heals for the specified amount. Cannot heal beyond max health. More...
 
void stun (sf::Time const &duration)
 Get stunned. Become stunned for the specified amount of time. Stuns do not stack. If a subsequant stun is applied, the stun with the longer duration is used. i.e. A stun of 1 second cannot cancel out a 5 second stun, nor does it becoe a 6 second stun. More...
 
void beTaunted (std::shared_ptr< Pawn > const &taunter)
 Become forced to attack th taunter. Changes combat target to be the taunter. Has no associated duration so subsequent taunts will override each other. More...
 
bool offerTarget (std::shared_ptr< Pawn > const &target)
 Offer a potential target to the Pawn. Offer a target to the Pawn, who then decides whether to accept it or not. More...
 
bool targetIsDead () const
 
void wait (float seconds)
 Disallows the pawn to march for the specified time. More...
 
int getHealth () const
 
State getState () const
 Gets the current state of the Pawn. More...
 
bool isDead () const
 
Faction getFaction () const
 
void setOnDeath (std::function< void(Pawn *)> const &callback)
 
std::weak_ptr< Pawn > const & getCombatTarget () const
 
Damage::Reduction const & getArmour () const
 
Damage::Reduction const & getMagicResist () const
 
sf::Color getBloodColor () const
 
virtual void onCollide (std::shared_ptr< Collidable > &other, sf::Vector2f const &mtv)
 Called whenever the Pawn collides with something. Virtual method that is invoked whenver this Pawn collides with something. Moves the Pawn a portion of the minimum translation vector. More...
 
- Public Member Functions inherited from Actor
 Actor (sf::Texture &texture, sf::Shape *collisionMask, sf::Vector2f const &maskOffset)
 
 Actor (tinyxml2::XMLElement *xml)
 
void animate (sf::Time const &elapsedTime)
 Updates the animator and applies it to ourself.
 
bool isPlayingAnimation () const
 Returns true if an animation is currently playing.
 
std::string getPlayingAnimation () const
 Gets the name of the playing animation. Undefined behaviour if no animation playing.
 
void playAnimation (std::string const &name, bool loop=false)
 Begins playing an animation by name.
 
void setVisible (bool isVisible=true)
 
bool toggleVisible ()
 
bool getVisible () const
 
virtual void draw (sf::RenderTarget &target) const
 
- Public Member Functions inherited from collision::Collidable
 Collidable (sf::Shape *mask, sf::Vector2f offset)
 
 Collidable (Collidable const &other)
 
 Collidable (tinyxml2::XMLElement *xml)
 Constructs a Collidable from an xml tag. Tag requires pointCoint and type attributes in addition to child tags depending on type specified. More...
 
const sf::Shape * getMask () const
 
void setMask (sf::Shape *mask, sf::Vector2f offset)
 
virtual void onCollide (std::shared_ptr< Collidable > &other, sf::Vector2f const &mtv)
 Called when we collide with something.
 
void setDebugColour (sf::Color const &c)
 
void debug_draw (sf::RenderTarget &target)
 
void getAxies (std::vector< sf::Vector2f > &axiesVector)
 Gets all axies of the mask. Gets all axies of the mask. Currently inefficient due to the fact that it iterates over all points and returns all axies (a duplicate of each axis is included!). More...
 
size_t getPointCount () const
 Gets the number of points in the mask. Calls mask->getPoint() and returns the result.
 
sf::Vector2f projectOntoAxis (sf::Vector2f &axis) const
 Projects the mask onto an axis. Projects each point of the mask onto an axis and returns the min and max points it covers on that axis. More...
 

Protected Member Functions

virtual void doAttack (float secondsElapsed) override
 Override of Pawn::doAttack that allows Hero to attack and move at the same time.
 
void playMoveSound ()
 
- Protected Member Functions inherited from Pawn
void turnToFaceDirection (sf::Vector2f const &dir)
 
virtual void calculateAnimation ()
 
virtual void calculateState (sf::Vector2f const &goalDisplacement)
 
virtual void doMarch (sf::Vector2f const &goalDisplacement, float secondsElapsed)
 
void stopWaiting ()
 
- Protected Member Functions inherited from collision::Collidable
void updateCollidableMask (sf::Vector2f const &newPosition)
 Updates the position of the mask. Updates the position of the mask to equal newPosition plus the offset. More...
 

Static Protected Member Functions

static bool shouldPlayMoveSound ()
 

Protected Attributes

float mSecondsSinceRegen
 
const float M_REGEN_INTERVAL
 Seconds to wait between applying health regen.
 
const unsigned int M_HEALTH_REGEN
 Amount of health to regenerate per second.
 
std::vector< sf::Sound > mMoveSounds
 
- Protected Attributes inherited from Pawn
Faction mFaction
 
State mState
 
int mHealth
 
const int M_MAX_HEALTH
 
Damage::Reduction mArmour
 
Damage::Reduction mMagicResist
 
Damage::Type mDamageType
 
float mAttackRange
 
int mMovementSpeed
 
int mAttackDamage
 
float mAttacksPerSecond
 
float mTimeSinceAttack
 
std::weak_ptr< PawnmCombatTarget
 
sf::Time mStunDuration
 
sf::Time mTimeStunned
 
sf::Vector2f mDestination
 
sf::Sound mAttackSound
 
std::weak_ptr< Pawnself
 
- Protected Attributes inherited from Actor
bool mVisible
 

Additional Inherited Members

- Public Types inherited from Pawn
enum  Faction { PLAYER, ENEMY, NEUTRAL }
 
enum  State {
  IDLE, MARCHING, ATTACKING, STUNNED,
  DEAD
}
 

Detailed Description

Pawn that can move and attack simultaneously and regenerates health.

Member Function Documentation

void Hero::setDestination ( sf::Vector2f const &  destination)
finaloverridevirtual

Sets the Pawn's destination.

Remarks
Pawns move straight toward their destination.
Parameters
destinationThe Pawn's new destination.

Reimplemented from Pawn.

void Hero::update ( sf::Time const &  elapsedTime)
overridevirtual

Updates the Pawn. State becomes MARCHING is goal is further than attack range. State becomes ATTACKING if has a target and target is within attack range. Else state become IDLE.

Moves toward goal if MARCHING. Attacks target if ATTACKING, taking into account attacks per second. Does nothing if state is somethig else.

Calls updateCollidableMask with current position at end of method.

Parameters
elapsedTimeThe amount of time elapsed since last update tick.

Reimplemented from Pawn.


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