src/Rope.hh
author terom
Sun, 07 Dec 2008 01:18:59 +0000
changeset 241 e95b1602d836
parent 235 0a0c729365ee
child 248 e40ef56dc62c
permissions -rw-r--r--
implement the ROT (Rope Over TCP) protocol
#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 "GraphicsPointer.hh"

enum RopeState {
    ROPE_FOLDED, 
    ROPE_FLYING, 
    ROPE_FIXED 
};

class Rope : public PhysicsObject {
    private:
        // the owner
        Player &player;

        // How long is the rope in its unstrected state
        float length;
        
        // basic state
        RopeState state;
        
    protected:
        /*
         * Attach the rope, so disable the PhysicsObject and change state
         */
        virtual void onCollision (void);

        /*
         * If the rope is currently longer than length, this returns ROPE_FORCE, else 0
         */
        virtual float getPivotForce (PhysicsObject *bob);

    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);

        /*
         * For use by NetworkClient
         */
        void updateState (RopeState state, Vector position, Vector velocity, float length);
        void updateLength (float length);
        
        /*
         * Just draws it
         */ 
        virtual void draw (Graphics *c) const;
};

#endif