GEJM  1.0.0.0
a 2D platformer made by students
Public Member Functions | Protected Attributes | List of all members
Creature Class Reference

#include <Creature.h>

Inheritance diagram for Creature:
SolidObject Object MonsterCreature PlayerCreature

Public Member Functions

 Creature (double x=0.0, double y=0.0, double width=1.0, double height=1.0, Uint8 health=1)
 
virtual ~Creature ()
 
void savePrevious () override
 
void moveBy (double x, double y)
 
void hurt (Sint8 damage)
 
void setSpeedVector (double x, double y)
 
void addCollisionState (CollisionState state)
 
virtual void onCollision (SolidObject *collider)
 
Uint8 getHealth () const
 
bool getIsAlive () const
 
bool getIsInvulnerable () const
 
bool getWasInvulnerable () const
 
double getSpeedX () const
 
double getSpeedY () const
 
CollisionState getCollisionState () const
 
Creatureoperator= (Creature const &)=delete
 
- Public Member Functions inherited from SolidObject
 SolidObject (double x=0.0, double y=0.0, double width=1.0, double height=1.0)
 
virtual ~SolidObject ()
 
- Public Member Functions inherited from Object
 Object (double x=0.0, double y=0.0, double width=1.0, double height=1.0)
 
virtual ~Object ()
 
void destroy ()
 
double getY () const
 
double getX () const
 
double getWidth () const
 
double getHeight () const
 
double getPrevX () const
 
double getPrevY () const
 
bool getDestroyed () const
 

Protected Attributes

Uint8 health
 
Uint32 const invFrames
 
bool isAlive
 
bool isInvulnerable
 
bool wasInvulnerable
 
double speedX
 
double speedY
 
CollisionState collisionState
 
Timer invTimer
 
- Protected Attributes inherited from Object
double x
 
double y
 
double width
 
double height
 
double prevX
 
double prevY
 
bool destroyed
 

Detailed Description

Creature is the base class of all creatures that can be possessed by players or AI. They are the physical representations of players and creatures in a level. It derives from SolidObject.

See also
SolidObject

Constructor & Destructor Documentation

Creature::Creature ( double  x = 0.0,
double  y = 0.0,
double  width = 1.0,
double  height = 1.0,
Uint8  health = 1 
)

The default constructor of Creature.

Parameters
xX position of Creature. Defaults to 0.0
yY position of Creature. Defaults to 0.0
widthwidth of Creature. Defaults to 1.0
heightheight of Creature. Defaults to 1.0
healthhealth of Creature. Defaults to 1
See also
SolidObject
health

Creature implementation The default constructor of Creature.

Parameters
xX position of Creature. Defaults to 0.0
yY position of Creature. Defaults to 0.0
widthwidth of Creature. Defaults to 1.0
heightheight of Creature. Defaults to 1.0
healthhealth of Creature. Defaults to 1
See also
SolidObject
health
Creature::~Creature ( )
virtual

The default destructor.

Member Function Documentation

void Creature::addCollisionState ( CollisionState  state)

Changes current collisionState of Creature by OR assignment of parameter.

Parameters
stateCollisionState to be added to member collisionState
Returns
void
CollisionState Creature::getCollisionState ( ) const

Get current collisionState of Creature.

Returns
CollisionState
Uint8 Creature::getHealth ( ) const

Get current health of Creature.

Returns
Uint8
bool Creature::getIsAlive ( ) const

Check if Creature is alive.

Returns
bool
bool Creature::getIsInvulnerable ( ) const

Check if Creature is invulnerable.

Returns
bool
double Creature::getSpeedX ( ) const

Get current velocity of Creature on X-axis.

Returns
double
double Creature::getSpeedY ( ) const

Get current velocity of Creature on Y-axis.

Returns
double
bool Creature::getWasInvulnerable ( ) const

Check if Creature was invulnerable.

Returns
bool
void Creature::hurt ( Sint8  damage)

Changes health of Creature. If damage equals 127 or is less than or equal to 0 then it ignores invulnerability. Else deal damage only if Creature is not Invulnerable and set invulnerability of Creature.

Parameters
damagehow much damage Creature takes
Returns
void
void Creature::moveBy ( double  x,
double  y 
)

Changes relatively current position of Creature.

Parameters
xrelative change of position on X axis
yrelative change of position on Y axis
Returns
void
void Creature::onCollision ( SolidObject collider)
virtual

Virtual function for resolving collision. Default implementation ignores Coin and Trigger and solves collision with SolidObject.

Parameters
collidera pointer to a SolidObject with which Creature is colliding
Returns
void

Reimplemented in MonsterCreature, and PlayerCreature.

Creature& Creature::operator= ( Creature const &  )
delete

Assignment operator is deleted because of constant member initialized on Construction.

void Creature::savePrevious ( )
overridevirtual

Changes members that hold information about previous step to hold current state of Creature. Also checks if invTimer has passed and disables invulnerability. Sets current collisionState to noCollision.

Returns
void

Reimplemented from Object.

void Creature::setSpeedVector ( double  x,
double  y 
)

Changes current velocity vector of Creature.

Parameters
xnew velocity value on X axis
ynew velocity value on Y axis
Returns
void

Member Data Documentation

CollisionState Creature::collisionState
protected

Current CollisionState of Creature.

Uint8 Creature::health
protected

Current health of Creature.

Uint32 const Creature::invFrames
protected

Constant number of invulnerability frames of Creature.

Timer Creature::invTimer
protected

Timer used to calculate a period of invulnerability of Creature.

bool Creature::isAlive
protected

Current liveness of Creature.

bool Creature::isInvulnerable
protected

Current state of invulnerability of Creature.

double Creature::speedX
protected

Current velocity on X-axis of Creature.

double Creature::speedY
protected

Current velocity on Y-axis of Creature.

bool Creature::wasInvulnerable
protected

Previous state of invulnerability of Creature.


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