See the file LICENSE for the license governing this code.
LevelObject > Character
Character represents a LevelObject that has hitpoints.
Characters are alive. They can take damage, react and become invincible for a time.
hp (integer) to specify the amount of hitpoints and max hitpoints the character has.damage (integer) to specify the amount of damage this character deals.
#pragma once
#include "Headers.h"
class Character : public LevelObject
{
public:
virtual const char* const profileName()=0;
Character();
virtual ~Character();Set properties for this character.
virtual void setProperties(Level& level, ValueMap& dict);Create the character’s physical body.
virtual void createBody(Physics& physics, void* userData);Adds fixtures to the character’s physical body.
virtual void createFixtures();Return true if the character is alive.
virtual bool isAlive();Return true if the character is invincible.
virtual bool isInvincible() const;React by setting a velocity and duration during which the character cannot be controlled.
Used to create “knock back” effects.
Duration is controlled via the member reactionDuration.
virtual void react(const Vec2& velocity);Return true if the character is reacting.
virtual bool isReacting() const;Take damage from the given LevelObject. The object is queried for how much damage it deals.
void takeDamage(LevelObject* o);Called when the character’s hitpoints have reached zero.
virtual void die();Used to disable the character. Called when the character dies and also when the level is loaded and it is determined that the character is already dead.
virtual void disable();Tick and animate the character.
virtual void tick(float delta);
virtual void animate(float delta); protected:How much health this character has.
GETTER_SETTER(int, hp, HP);The maximum amount of health this character can have.
GETTER_SETTER(int, maxHP, MaxHP);The amount of time the character is invincible after taking damage.
GETTER_SETTER(double, invincibleDuration, InvincibleDuration);Start of invincibility time.
double invincibleStartTime;Timer for reaction (character not meant to change velocity during reaction).
float reactionTimer;Duration for reaction.
float reactionDuration;
private:
typedef LevelObject super;
typedef Character self;
bool dead;
};
Core
Object types