src/Projectile.hh
author Tero Marttila <terom@fixme.fi>
Wed, 21 Jan 2009 23:07:22 +0200
branchnew_graphics
changeset 412 721c60072091
parent 309 05a39422c81e
child 417 c503e0c6a740
permissions -rw-r--r--
new graphics code compiles... no, it doesn't work yet
#ifndef PROJECTILE_HH
#define PROJECTILE_HH
 
class Projectile;

#include "GameState.hh"
#include "Player.hh"
#include "PhysicsObject.hh"
#include "Timer.hh"
#include "Types.hh"

#include "Graphics/Drawable.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;
    
    Weapon *weapon;

    /**
     * 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::Display &display, PixelCoordinate camera) const;

    /**
     * Get damage inflicted by this projectile.
     *
     * @return Damage inflicted by projectile.
     */
    Health getDamage ();

    /**
     * Adds one kill to projectile owner.
     */
    void addKillToOwner ();

    /**
     * Return the owner of the projectile.
     */
    const Player* getOwner (); 

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

    /**
     * This Projectile has hit the given player.
     *
     * This Projectile inflicts a certain amount of damage on the player. We are not destroyed, this can be called
     * multiple times...
     */
    virtual void onHitPlayer (Player *player);
    
    /**
     * Call onDestroy, removingGround
     */
    virtual void onCollision (Vector collisionPoint, PhysicsObject *other);

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