--- a/src/proto2/Dimension.hh Mon Nov 10 16:40:40 2008 +0000
+++ b/src/proto2/Dimension.hh Wed Nov 12 13:59:01 2008 +0000
@@ -3,23 +3,7 @@
#include <iostream>
-class Dimension {
- public:
- uint32_t w;
- uint32_t h;
-
- Dimension (uint32_t w, uint32_t h) : w(w), h(h) { }
-};
-
-class PositionDelta {
- public:
- int32_t dx;
- int32_t dy;
-
- PositionDelta (int32_t dx, int32_t dy) : dx(dx), dy(dy) { }
-};
-
-class Coordinate {
+class Vector {
public:
uint32_t x;
uint32_t y;
@@ -43,6 +27,10 @@
uint32_t scaledY() { return y; }
};
+typedef Vector Dimension;
+typedef Vector PositionDelta;
+typedef Vector Coordinate;
+
std::ostream& operator<< (std::ostream &s, const Coordinate &c);
std::ostream& operator<< (std::ostream &s, const PositionDelta &c);
--- a/src/proto2/GameState.hh Mon Nov 10 16:40:40 2008 +0000
+++ b/src/proto2/GameState.hh Wed Nov 12 13:59:01 2008 +0000
@@ -19,70 +19,41 @@
// forward-declare GameState
class GameState;
-class Player {
- protected:
- Coordinate position;
-
- GameState &state;
-
+class Player : public PhysicsObject {
public:
- Player(GameState &state, Coordinate c, bool visible) : position(c), state(state), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {}
+ Player(GameState &state, Coordinate c, bool visible) :
+ PhysicsObject(...), 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);
-
};
class LocalPlayer : public Player {
protected:
- LocalPlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { }
+ LocalPlayer (Coordinate c, bool visible) : Player(c, visible) { }
public:
- virtual bool move (PositionDelta d) {
- return updatePosition(position + d);
- }
+ virtual bool handleMove (PlayerInput_Move input);
};
class RemotePlayer : public Player {
protected:
- RemotePlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { }
-
+ RemotePlayer (Coordinate c, bool visible) : Player(c, 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(...), 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
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/proto2/Input.hh Wed Nov 12 13:59:01 2008 +0000
@@ -0,0 +1,11 @@
+#ifndef INPUT_HH
+#define INPUT_HH
+
+enum PlayerInput_Move {
+ MOVE_UP = 0x01,
+ MOVE_DOWN = 0x02,
+ MOVE_LEFT = 0x04,
+ MOVE_RIGHT = 0x08,
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/proto2/Physics.hh Wed Nov 12 13:59:01 2008 +0000
@@ -0,0 +1,45 @@
+#ifndef PHYSICS_HH
+#define PHYSICS_HH
+
+#include "Vector.hh"
+
+const uint16_t PHYSICS_TICK_MS = 50;
+const uint16_t PHYSICS_WORLD_WIDTH = 800;
+const uint16_t PHYSICS_WORLD_HEIGHT = 600;
+
+class PhysicsWorld {
+ protected:
+ std::vector<PhysicsObject*> objects;
+ Vector dimensions;
+
+ PhysicsWorld (Vector dimensions);
+
+ public:
+ void addObject (PhysicsObject *object);
+
+ void tick (void);
+};
+
+class PhysicsObject {
+ protected:
+ Vector position;
+ Vector velocity;
+ Vector force;
+ uint16_t mass;
+
+ PhysicsObject (mass, position, velocity, force);
+
+ private:
+ void updatePosition (void);
+
+ protected:
+ void applyForce (Vector force);
+ void updatePhysics (Vector position, Vector velocity, Vector force);
+
+ public:
+ Vector getPosition (void);
+
+ void tick (void);
+};
+
+#endif