src/Projectile.hh
author terom
Mon, 08 Dec 2008 12:46:37 +0000
changeset 283 7540b0859579
parent 276 87434abc1ba1
child 296 4d3ebaa29430
permissions -rw-r--r--
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
#ifndef PROJECTILE_HH
#define PROJECTILE_HH
 
class Projectile;

#include "GameState.hh"
#include "PhysicsObject.hh"
#include "Timer.hh"
#include "GraphicsPointer.hh"

/**
 * A projectile is a flying PhysicsObject, created by firing a player's weapon. It has an initial velocity, is
 * represented as a diamond-shape with the given "radius", can explode or bounce on collisions, expires at some point,
 * and can remove ground around it upon exploding.
 */
class Projectile : public PhysicsObject {
protected:
    /**
     * Which player fired this projectile?
     */
    Player *player;

    /**
     * Projectiles can be inivisble, e.g. for digging
     */
    bool visible;
    
    /**
     * The projectile is diamond-shaped, and this is the dimanond's "radius"
     */
    float radius;

    /**
     * The radius of earth removed by this projectile on impact
     */
    float explosionRadius;

    /**
     * How many ticks this projectile lasts before being expiring
     */
    TickCount expire;

    /**
     * The tick we were spawned at
     */
    TickCount birth_tick;

public:
    /**
     * Constructs this projectile using the given position/velocity, pulling the rest of the parameter values from the
     * given weapon. The given player is assigned to this projectile. 
     */
    Projectile (Player *player, Vector position, Vector velocity, Weapon *weapon, bool visible = true);

    /**
     * Removes this from the world's list of projectiles
     */
    virtual ~Projectile (void);
    
    /**
     * Draw
     */
    virtual void draw (Graphics *g, PixelCoordinate camera) const;

protected:
    /**
     * Removes ground at given position if applicable, and destroys this PhysicsObject.
     *
     * This is overriden by Network.
     */
    virtual void onDestroy (Vector position, bool removeGround);
    
    /**
     * Call onDestroy, removingGround
     */
    virtual void onCollision (Vector collisionPoint, PhysicsObject *other);

    /**
     * If we have expired, call onDestory and removeGround
     */
    virtual void tick (TimeMS dt);
};
 
#endif