src/proto2/GameState.hh
author terom
Thu, 20 Nov 2008 23:45:33 +0000
branchno-netsession
changeset 41 ca80cd67785d
parent 35 e21cfda0edde
permissions -rw-r--r--
merge r64 through r88 from trunk
#ifndef GAMESTATE_HH
#define GAMESTATE_HH

#include "Physics.hh"
#include "Input.hh"

#include <list>
#include <stdexcept>

// in cells/kg
const uint16_t MAP_WIDTH = 800;
const uint16_t MAP_HEIGHT = 600;
const float MAP_GRAVITY = 1200.0;
const float PLAYER_MASS = 10.0;
const float PLAYER_MOVE_FORCE = 5000.0;
const float PLAYER_INITIAL_X = 400.0;
const float PLAYER_INITIAL_Y = 300.0;

// forward-declare GameState
class GameState;

class Player : public PhysicsObject {
    protected:
        GameState &state;
        bool visible;

    public:

        Player(GameState &state, Vector position, bool visible) : 
            PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { }

};

class LocalPlayer : public Player {
    protected:
        LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
    
    public:
        virtual void handleMove (PlayerInput_Move input);
};

class RemotePlayer : public Player {
    protected:
        RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
};

class GameState : public PhysicsWorld {
    public:
        std::list<Player*> player_list;

        // only one local player is supported
        LocalPlayer *local_player;

        GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) {

        }
       
        /*
         * This will return NULL if we don't have a local player - yet
         */
        LocalPlayer *getLocalPlayer (void) {
            return local_player;
        }
        
        void newLocalPlayer (LocalPlayer *player) {
            if (local_player)
                throw std::logic_error("newLocalPlayer called even though we already have a local player");

            player_list.push_back(player);

            local_player = player;
        }

        void newRemotePlayer (RemotePlayer *player) {
            player_list.push_back(player);
        }

        void removePlayer (Player *player) {
            player_list.remove(player);
        }
};

#endif