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 saiam@108: #include saiam@108: saiam@108: const float KG_PI = 3.14159265; 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; saiam@115: const float COLLISION_ELASTICITY = 0.4; saiam@115: 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; saiam@115: const float PLAYER_MIN_SPEED = 10.0; terom@22: saiam@108: const float CROSSHAIR_ANGLE_SPEED = PI/40; // TODO: Adjust this nireco@126: const float PLAYER_AIM_MIN = -KG_PI/4; // TODO: -- || -- saiam@108: const float PLAYER_AIM_MAX = KG_PI/2; // TODO: -- || -- saiam@108: terom@26: // forward-declare GameState terom@26: class GameState; terom@26: terom@42: class Player : public PhysicsObject { saiam@108: protected: saiam@108: GameState &state; saiam@108: bool visible; saiam@108: saiam@108: public: saiam@108: Player(GameState &state, Vector position, bool visible) : saiam@108: PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { saiam@108: saiam@108: std::vector shape(4); saiam@108: shape[0] = Vector(0,-18); saiam@108: shape[1] = Vector(6,-9); saiam@108: shape[2] = Vector(0,0); saiam@108: shape[3] = Vector(-6,-9); saiam@108: // Initialize the shape of the player (salmiakki shape) saiam@108: setShape(shape); saiam@108: } saiam@108: saiam@108: void debugInfo (); saiam@108: saiam@108: public: saiam@108: virtual void handleMove (PlayerInput_Move input); saiam@108: terom@3: terom@3: }; terom@3: nireco@116: class Shot : public PhysicsObject { nireco@116: protected: nireco@116: GameState &state; nireco@116: bool visible; nireco@116: uint32_t birth_tick; nireco@116: uint32_t death_tick; nireco@116: public: nireco@116: Shot(GameState &state, Vector position, bool visible) : nireco@116: PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { nireco@127: // Looks kind of dumb, for ammunition to have shape nireco@127: std::vector shape(4); nireco@127: shape[0] = Vector(-1, -1); nireco@127: shape[1] = Vector(-1, 1); nireco@127: shape[2] = Vector(1, 1); nireco@127: shape[3] = Vector(1, -1); nireco@127: setShape(shape); nireco@116: } nireco@116: private: nireco@116: virtual void onCollision(); nireco@116: }; nireco@116: terom@3: class LocalPlayer : public Player { saiam@108: protected: saiam@108: LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } terom@3: }; terom@3: terom@3: class RemotePlayer : public Player { saiam@108: protected: saiam@108: RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } terom@6: }; terom@6: terom@42: class GameState : public PhysicsWorld { saiam@108: public: saiam@108: std::list player_list; terom@8: saiam@108: // only one local player is supported saiam@108: LocalPlayer *local_player; terom@22: saiam@108: GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) { terom@22: saiam@108: } terom@42: saiam@108: /* saiam@108: * This will return NULL if we don't have a local player - yet saiam@108: */ saiam@108: LocalPlayer *getLocalPlayer (void) { saiam@108: return local_player; saiam@108: } terom@24: saiam@108: void newLocalPlayer (LocalPlayer *player) { saiam@108: if (local_player) saiam@108: throw std::logic_error("newLocalPlayer called even though we already have a local player"); terom@24: saiam@108: player_list.push_back(player); terom@24: saiam@108: local_player = player; saiam@108: } terom@24: saiam@108: void newRemotePlayer (RemotePlayer *player) { saiam@108: player_list.push_back(player); saiam@108: } saiam@108: saiam@108: void removePlayer (Player *player) { saiam@108: player_list.remove(player); saiam@108: } terom@6: }; terom@6: terom@3: #endif