See the file LICENSE for the license governing this code.
LevelObject > Projectile
Projectile
is a subclass of LevelObject
representing a projectile, something that flies through the air with a given velocity, may or may not be affected by gravity, may or may not collide with the Level
or other LevelObjects
and may or may not explode on impact.
Contains a vector, speed, damage, target class, etc.
#pragma once
#include "Headers.h"
class Projectile : public LevelObject
{
public:
enum
{
kInfinite = -99999,
};
virtual const char* const profileName() {return "Projectile";}
Projectile();
virtual ~Projectile();
The vector this projectile will move along.
GETTER(Vec2, vector, Vector);
void setVector(const Vec2& v);
Speed of the projectile in meters per second.
GETTER_SETTER(float, speed, Speed);
The number of hits a projectile can give before expiring.
GETTER_SETTER(float, hp, HP);
Amount of time this projectile will last.
GETTER_SETTER(float, lifeTimer, LifeTimer);
Delay until the projectile is launched.
GETTER_SETTER(float, delayTimer, DelayTimer);
The object that launched the projectile.
GETTER_SETTER(LevelObject*, attacker, Attacker);
Whether or not the projectile will impact any target, or a specific target class.
GETTER_SETTER(bool, attackAnyTarget, AttackAnyTarget);
The class name of the object that this projectile should seek to impact.
GETTER_SETTER(string, targetClass, TargetClass);
Set the objects properties.
virtual void setProperties(Level& level, ValueMap& dict);
Finds a target object.
virtual LevelObject* findTarget();
Launches the projectile.
virtual void launch();
Tick the projectile.
virtual void tick(float delta);
virtual void animate(float delta);
Called when the projectile is destroyed.
virtual void onDestroy();
private:
typedef LevelObject super;
typedef Projectile self;
protected:
Vec2 lastPos, motionCooldown;
float hitTimer;
};
Core
Object types