equal
deleted
inserted
replaced
14 #define PLAYER_DIM_W 10 |
14 #define PLAYER_DIM_W 10 |
15 #define PLAYER_DIM_H 10 |
15 #define PLAYER_DIM_H 10 |
16 #define MAP_DIM_W 800 |
16 #define MAP_DIM_W 800 |
17 #define MAP_DIM_H 640 |
17 #define MAP_DIM_H 640 |
18 |
18 |
|
19 // forward-declare GameState |
|
20 class GameState; |
|
21 |
19 class Player { |
22 class Player { |
20 protected: |
23 protected: |
21 Coordinate position; |
24 Coordinate position; |
22 |
25 |
|
26 GameState &state; |
|
27 |
23 public: |
28 public: |
24 |
29 |
25 Player(Coordinate c, bool visible) : position(c), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {} |
30 Player(GameState &state, Coordinate c, bool visible) : position(c), state(state), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {} |
26 |
31 |
27 PlayerType type; |
32 PlayerType type; |
28 Dimension dimensions; |
33 Dimension dimensions; |
29 bool visible; |
34 bool visible; |
30 |
35 |
36 /* |
41 /* |
37 * Update position to the given value. |
42 * Update position to the given value. |
38 * |
43 * |
39 * Returns true if valid move (not out of bounds), false otherwise (doesn't change position) |
44 * Returns true if valid move (not out of bounds), false otherwise (doesn't change position) |
40 */ |
45 */ |
41 bool updatePosition (Coordinate p) { |
46 bool updatePosition (Coordinate p); |
42 // unsigned... |
|
43 if (p.x > dimensions.w || p.y > dimensions.h) { |
|
44 // out-of-bounds |
|
45 return false; |
|
46 } |
|
47 |
|
48 // valid |
|
49 position = p; |
|
50 |
|
51 return true; |
|
52 } |
|
53 |
47 |
54 }; |
48 }; |
55 |
49 |
56 class LocalPlayer : public Player { |
50 class LocalPlayer : public Player { |
57 protected: |
51 protected: |
58 LocalPlayer (Coordinate c, bool visible) : Player(c, visible) { } |
52 LocalPlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { } |
59 |
53 |
60 public: |
54 public: |
61 virtual bool move (PositionDelta d) { |
55 virtual bool move (PositionDelta d) { |
62 return true; |
56 return updatePosition(position + d); |
63 |
|
64 //return updatePosition(position + d); |
|
65 } |
57 } |
66 }; |
58 }; |
67 |
59 |
68 class RemotePlayer : public Player { |
60 class RemotePlayer : public Player { |
69 protected: |
61 protected: |
70 RemotePlayer (Coordinate c, bool visible) : Player(c, visible) { } |
62 RemotePlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { } |
71 |
63 |
72 }; |
64 }; |
73 |
65 |
74 class GameState { |
66 class GameState { |
75 public: |
67 public: |
79 // only one local player is supported |
71 // only one local player is supported |
80 LocalPlayer *local_player; |
72 LocalPlayer *local_player; |
81 |
73 |
82 GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) { |
74 GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) { |
83 |
75 |
|
76 } |
|
77 |
|
78 /* |
|
79 * Check if the given coordinate is valid |
|
80 */ |
|
81 bool isValidCoordinate (const Coordinate &p) { |
|
82 // unsigned... |
|
83 return !(p.x > map_dimensions.w || p.y > map_dimensions.h); |
84 } |
84 } |
85 |
85 |
86 /* |
86 /* |
87 * This will return NULL if we don't have a local player - yet |
87 * This will return NULL if we don't have a local player - yet |
88 */ |
88 */ |