--- a/src/proto2/GameState.hh Mon Nov 10 21:58:38 2008 +0000
+++ b/src/proto2/GameState.hh Tue Nov 18 22:58:50 2008 +0000
@@ -1,88 +1,60 @@
#ifndef GAMESTATE_HH
#define GAMESTATE_HH
-#include "Dimension.hh"
+#include "Physics.hh"
+#include "Input.hh"
#include <list>
#include <stdexcept>
-enum PlayerType {
- PLAYER_LOCAL,
- PLAYER_REMOTE
-};
-
-#define PLAYER_DIM_W 10
-#define PLAYER_DIM_H 10
-#define MAP_DIM_W 800
-#define MAP_DIM_H 640
+// in meters/kg
+const float MAP_WIDTH = 100.0;
+const float MAP_HEIGHT = 100.0;
+const float MAP_GRAVITY = 9.81;
+const float PLAYER_MASS = 10.0;
+const float PLAYER_MOVE_FORCE = 500.0;
+const float PLAYER_INITIAL_X = 50.0;
+const float PLAYER_INITIAL_Y = 40.0;
// forward-declare GameState
class GameState;
-class Player {
+class Player : public PhysicsObject {
protected:
- Coordinate position;
-
GameState &state;
+ bool visible;
public:
- Player(GameState &state, Coordinate c, bool visible) : position(c), state(state), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {}
-
- PlayerType type;
- Dimension dimensions;
- bool visible;
-
- Coordinate getPosition (void) const {
- return position;
- }
-
- protected:
- /*
- * Update position to the given value.
- *
- * Returns true if valid move (not out of bounds), false otherwise (doesn't change position)
- */
- bool updatePosition (Coordinate p);
+ 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, Coordinate c, bool visible) : Player(state, c, visible) { }
+ LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
public:
- virtual bool move (PositionDelta d) {
- return updatePosition(position + d);
- }
+ virtual void handleMove (PlayerInput_Move input);
};
class RemotePlayer : public Player {
protected:
- RemotePlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { }
-
+ RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
};
-class GameState {
+class GameState : public PhysicsWorld {
public:
- Dimension map_dimensions;
std::list<Player*> player_list;
// only one local player is supported
LocalPlayer *local_player;
- GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) {
+ GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) {
}
-
- /*
- * Check if the given coordinate is valid
- */
- bool isValidCoordinate (const Coordinate &p) {
- // unsigned...
- return !(p.x > map_dimensions.w || p.y > map_dimensions.h);
- }
-
+
/*
* This will return NULL if we don't have a local player - yet
*/