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

// Pre-declarations since rope wants to know the Player
// and the Player wants to know the rope.
class Rope;

#include "Player.hh"
#include "PhysicsObject.hh"

#include "Graphics/Drawable.hh"

/**
 * The rope can be in one of three states...
 *
 * @see Rope
 */
enum RopeState {
    ROPE_FOLDED,    //<<< The rope is folded, out of sight, and not in use
    ROPE_FLYING,    //<<< The rope is flying through the air as a projectile
    ROPE_FIXED      //<<< The rope is attached to something
};

/**
 * A rope is a PhysicsObject that can be thrown, whereupon it then flies until it hits something, whereupon
 * it attaches to that, and sets itself as the player's pivot.
 */
class Rope : public PhysicsObject {
private:
    /** the owner */
    Player &player;

    /** How long is the rope in its unstreched state */
    float length;
        
    /** Current state */
    RopeState state;

protected:
    /**
     * Attach the rope, so disable the PhysicsObject and change state
     * @param collisionPoint Where the rope has hit the ground.
     */
    virtual void onCollision (Vector collisionPoint, PhysicsObject *other);

public:
    Rope(Player &player);
        
    /**
     * Throw the rope, so it flies up and away: o._-*
     */
    void throwRope (void);

    /**
     * Release the rope, so if it's currently fixed or flying, then fold it 
     */
    void release (void);

    /**
     * Climb up/down the rope
     */
    void changeLength (float delta);
        
    /**
     * Current state
     */
    RopeState getState (void);

    /**
     * Current length
     */
    float getLength (void);

    /**
     * If this Rope's player is pivoted to another player, return that player-pivot, else return NULL
     */
    Player *getPivotPlayer (void);

    /*
     * For use by NetworkClient
     */
    void updateState (RopeState state, Vector position, Vector velocity, float length, Player *pivot_player);
    void updateLength (float length);
        
    virtual void tick (TimeMS dt);

    /*
     * Draw the rope, in the FLYING/FIXED state
     */ 
    virtual void draw (graphics::Display &display, PixelCoordinate camera);
};

#endif