src/Player.hh
author saiam
Sun, 07 Dec 2008 19:40:40 +0000
changeset 251 6a6208e5c7a1
parent 248 e40ef56dc62c
child 255 99431fdb0dc8
permissions -rw-r--r--
Added recoil parameter for weapons, but it is not used yet.
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     1
#ifndef PLAYER_HH
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     2
#define PLAYER_HH
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     3
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     4
class Player;
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
     5
class LocalPlayer;
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
     6
class RemotePlayer;
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     7
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: 228
diff changeset
     8
#include "Weapon.hh"
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
     9
#include "GameState.hh"
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    10
#include "PhysicsObject.hh"
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 200
diff changeset
    11
#include "Input.hh"
225
22ecb9cb9245 Rope can be drawn.
ekku
parents: 223
diff changeset
    12
#include "Rope.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: 228
diff changeset
    13
#include "GraphicsPointer.hh"
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 209
diff changeset
    14
#include <vector>
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    15
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    16
class Player : public PhysicsObject {
228
dbc1bb7a98b5 Rope has forces
ekku
parents: 225
diff changeset
    17
    friend class Rope;
dbc1bb7a98b5 Rope has forces
ekku
parents: 225
diff changeset
    18
222
293ddf4c067d reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents: 221
diff changeset
    19
    public:
293ddf4c067d reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents: 221
diff changeset
    20
        GameState &state;
293ddf4c067d reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents: 221
diff changeset
    21
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    22
    protected:
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    23
        // XXX: not used
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    24
        bool visible;
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    25
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    26
        // our weapons
236
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    27
        std::vector<Weapon*> weapons;
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 209
diff changeset
    28
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    29
        // the index of the currently selected weapon
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    30
        unsigned int selectedWeapon;
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    31
        
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    32
        // we have a rope
225
22ecb9cb9245 Rope can be drawn.
ekku
parents: 223
diff changeset
    33
        Rope rope;
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    34
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 237
diff changeset
    35
        // XXX: hmm... updated where?
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 215
diff changeset
    36
        int animation_step;
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 215
diff changeset
    37
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    38
        // default constructor for use with virtual inheritance... it's not defined
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    39
        Player (void);
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    40
        Player (GameState &state, Vector position, bool visible); 
236
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    41
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    42
        /*
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    43
         *  Used by the network code to execute various actions
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    44
         */
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    45
        virtual void handleDig (Vector position, float radius);
236
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    46
        virtual void handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity);
237
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    47
        virtual void handleChangeWeapon (unsigned int weaponIndex);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    48
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    49
        // Called by rope to handle state changes, these don't do anything by default
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    50
        virtual void handleRopeState (RopeState state);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
    51
        virtual void handleRopeLength (float length);
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    52
        
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    53
        /*
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
    54
         * The currently selected weapon
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    55
         */
236
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    56
        Weapon* getCurrentWeapon();
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 209
diff changeset
    57
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    58
    public:
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    59
        /*
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    60
         * Prints random things via Engine::log
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    61
         */
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    62
        void printDebugInfo ();
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    63
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    64
        /*
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    65
         * Overrides PhysicsObject::tick to also advance game state
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    66
         */
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    67
        virtual void tick (TimeMS dt);
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    68
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    69
        /*
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    70
         * Drawing requires the skin texture, which is loaded on-demand when draw is called
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    71
         */
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    72
        static bool skin_loaded;
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    73
        static CL_Surface skin_surface;
248
e40ef56dc62c scrolling looks like it works
nireco
parents: 241
diff changeset
    74
        virtual void draw (Graphics *g, Vector camera = Vector(0, 0));
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    75
};
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    76
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    77
class LocalPlayer : public virtual Player {
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
    78
    private:
236
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    79
        /*
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    80
         * Calculates projectil position/velocity and calls handleCreateProjectile
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    81
         */
0048ba274152 move weapons definition out to Weapons.cc
terom
parents: 235
diff changeset
    82
        void fireWeapon (Weapon *weapon);
237
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    83
        
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    84
        /*
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    85
         * Change weapon index, should be negative or positive 1
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    86
         */
3d5465bcb67d tweak weapon params and improve weapon changing
terom
parents: 236
diff changeset
    87
        void changeWeapon (int delta);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
    88
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
    89
    public:
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    90
        /*
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    91
         * Called to invoke some action on this player that we control, either by Graphics or NetworkServer.
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    92
         *
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    93
         * NetworkClientLocalPlayer overrides this to send the input to the server, which then handles it
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    94
         */
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    95
        virtual void handleInput (PlayerInput input);
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: 228
diff changeset
    96
        
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 228
diff changeset
    97
        /*
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 228
diff changeset
    98
         * As Player, but also draws the current weapon name if displayWeapon
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 228
diff changeset
    99
         */
248
e40ef56dc62c scrolling looks like it works
nireco
parents: 241
diff changeset
   100
        virtual void draw (Graphics *g, bool displayWeapon, Vector camera);
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   101
};
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   102
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
   103
class RemotePlayer : public virtual Player {
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 205
diff changeset
   104
    protected:
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   105
};
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   106
 
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   107
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
   108
#endif