src/Rope.hh
author terom
Sun, 07 Dec 2008 20:07:28 +0000
changeset 255 99431fdb0dc8
parent 252 25054ce94d07
child 273 eeb699e1d908
permissions -rw-r--r--
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     1
#ifndef ROPE_HH
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     2
#define ROPE_HH
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     3
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     4
// Pre-declarations since rope wants to know the Player
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     5
// and the Player wants to know the rope.
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     6
class Rope;
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     7
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     8
#include "Player.hh"
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     9
#include "PhysicsObject.hh"
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 231
diff changeset
    10
#include "GraphicsPointer.hh"
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    11
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    12
enum RopeState {
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    13
    ROPE_FOLDED, 
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    14
    ROPE_FLYING, 
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    15
    ROPE_FIXED 
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    16
};
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    17
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    18
class Rope : public PhysicsObject {
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    19
    private:
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    20
        // the owner
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    21
        Player &player;
228
dbc1bb7a98b5 Rope has forces
ekku
parents: 225
diff changeset
    22
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    23
        // How long is the rope in its unstrected state
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    24
        float length;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    25
        
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    26
        // basic state
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    27
        RopeState state;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    28
        
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    29
    protected:
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    30
        /**
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    31
         * Attach the rope, so disable the PhysicsObject and change state
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    32
         * @param collisionPoint Where the rope has hit the ground.
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    33
         */
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    34
        virtual void onCollision (Vector collisionPoint);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    35
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    36
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    37
         * If the rope is currently longer than length, this returns ROPE_FORCE, else 0
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    38
         */
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    39
        virtual float getPivotForce (PhysicsObject *bob);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    40
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    41
    public:
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    42
        Rope(Player &player);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    43
        
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    44
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    45
         * Throw the rope, so it flies up and away: o._-*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    46
         */
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    47
        void throwRope (void);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    48
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    49
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    50
         * Release the rope, so if it's currently fixed or flying, then fold it 
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    51
         */
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    52
        void release (void);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    53
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    54
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    55
         * Climb up/down the rope
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    56
         */
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    57
        void changeLength (float delta);
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    58
        
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    59
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    60
         * Current state
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    61
         */
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    62
        RopeState getState (void);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    63
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    64
        /*
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    65
         * Current length
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    66
         */
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    67
        float getLength (void);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    68
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    69
        /*
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    70
         * For use by NetworkClient
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    71
         */
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    72
        void updateState (RopeState state, Vector position, Vector velocity, float length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    73
        void updateLength (float length);
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    74
        
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    75
        virtual void tick (TimeMS dt);
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    76
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    77
        /*
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    78
         * Just draws it
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    79
         */ 
255
99431fdb0dc8 add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents: 252
diff changeset
    80
        virtual void draw (Graphics *c, PixelCoordinate camera);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    81
};
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    82
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    83
#endif