terom@3: #ifndef GAMESTATE_HH terom@3: #define GAMESTATE_HH terom@3: terom@50: #include "Physics.hh" terom@50: #include "Input.hh" ekku@4: terom@5: #include terom@22: #include terom@5: ekku@79: // in cells/kg ekku@79: const uint16_t MAP_WIDTH = 800; ekku@79: const uint16_t MAP_HEIGHT = 600; ekku@88: const float MAP_GRAVITY = 1200.0; terom@60: const float PLAYER_MASS = 10.0; ekku@79: const float PLAYER_MOVE_FORCE = 5000.0; ekku@79: const float PLAYER_INITIAL_X = 400.0; ekku@79: const float PLAYER_INITIAL_Y = 300.0; terom@22: terom@26: // forward-declare GameState terom@26: class GameState; terom@26: terom@42: class Player : public PhysicsObject { terom@50: protected: terom@60: GameState &state; terom@60: bool visible; terom@50: terom@24: public: ekku@91: Player(GameState &state, Vector position, bool visible) : ekku@91: PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { terom@3: ekku@91: std::vector shape(4); ekku@94: shape[0] = Vector(0,-18); ekku@94: shape[1] = Vector(6,-9); ekku@94: shape[2] = Vector(0,0); ekku@94: shape[3] = Vector(-6,-9); ekku@91: // Initialize the shape of the player (salmiakki shape) ekku@91: setShape(shape); ekku@91: } terom@24: ekku@94: void debugInfo (); terom@96: terom@96: public: terom@96: virtual void handleMove (PlayerInput_Move input); terom@3: }; terom@3: terom@3: class LocalPlayer : public Player { terom@24: protected: terom@60: LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } terom@3: }; terom@3: terom@3: class RemotePlayer : public Player { terom@24: protected: terom@60: RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } terom@6: }; terom@6: terom@42: class GameState : public PhysicsWorld { terom@24: public: terom@24: std::list player_list; terom@8: terom@24: // only one local player is supported terom@24: LocalPlayer *local_player; terom@22: terom@60: GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) { terom@22: terom@24: } terom@42: terom@25: /* terom@25: * This will return NULL if we don't have a local player - yet terom@25: */ terom@25: LocalPlayer *getLocalPlayer (void) { terom@25: return local_player; terom@24: } terom@24: terom@24: void newLocalPlayer (LocalPlayer *player) { terom@24: if (local_player) terom@24: throw std::logic_error("newLocalPlayer called even though we already have a local player"); terom@24: terom@24: player_list.push_back(player); terom@24: terom@24: local_player = player; terom@24: } terom@24: terom@24: void newRemotePlayer (RemotePlayer *player) { terom@24: player_list.push_back(player); terom@24: } terom@24: terom@24: void removePlayer (Player *player) { terom@24: player_list.remove(player); terom@24: } terom@6: }; terom@6: terom@3: #endif