src/Player.hh
author saiam
Mon, 08 Dec 2008 00:05:45 +0000
changeset 273 eeb699e1d908
parent 255 99431fdb0dc8
child 274 c35307e8645c
permissions -rw-r--r--
Made forceq to contain time again.
#ifndef PLAYER_HH
#define PLAYER_HH

class Player;
class LocalPlayer;
class RemotePlayer;

#include "Weapon.hh"
#include "GameState.hh"
#include "PhysicsObject.hh"
#include "Input.hh"
#include "Rope.hh"
#include "GraphicsPointer.hh"
#include <vector>

class Player : public PhysicsObject {
    friend class Rope;

    public:
        GameState &state;

    protected:
        // XXX: not used
        bool visible;

        // our weapons
        std::vector<Weapon*> weapons;

        // the index of the currently selected weapon
        unsigned int selectedWeapon;
        
        // we have a rope
        Rope rope;

        // XXX: hmm... updated where?
        int animation_step;

        // default constructor for use with virtual inheritance... it's not defined
        Player (void);
        Player (GameState &state, Vector position, bool visible); 

        /*
         *  Used by the network code to execute various actions
         */
        virtual void handleDig (Vector position, float radius);
        virtual void handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity);
        virtual void handleChangeWeapon (unsigned int weaponIndex);

        // Called by rope to handle state changes, these don't do anything by default
        virtual void handleRopeState (RopeState state);
        virtual void handleRopeLength (float length);
        
        /*
         * The currently selected weapon
         */
        Weapon* getCurrentWeapon();

    public:
        /*
         * Prints random things via Engine::log
         */
        void printDebugInfo ();

        /*
         * Overrides PhysicsObject::tick to also advance game state
         */
        virtual void tick (TimeMS dt);

        /*
         * Drawing requires the skin texture, which is loaded on-demand when draw is called
         */
        static bool skin_loaded;
        static CL_Surface skin_surface;
        virtual void draw (Graphics *g, PixelCoordinate camera);
};

class LocalPlayer : public virtual Player {
    private:
        /*
         * Calculates projectil position/velocity and calls handleCreateProjectile
         */
        void fireWeapon (Weapon *weapon);
        
        /*
         * Change weapon index, should be negative or positive 1
         */
        void changeWeapon (int delta);

    public:
        /*
         * Called to invoke some action on this player that we control, either by Graphics or NetworkServer.
         *
         * NetworkClientLocalPlayer overrides this to send the input to the server, which then handles it
         */
        virtual void handleInput (PlayerInput input);
        
        /*
         * As Player, but also draws the current weapon name if displayWeapon
         */
        virtual void draw (Graphics *g, bool displayWeapon, PixelCoordinate camera);
};

class RemotePlayer : public virtual Player {
    protected:
};
 

#endif