| author | saiam |
| Sat, 29 Nov 2008 20:59:50 +0000 | |
| changeset 136 | 3a15a5937f7a |
| parent 127 | 241830182118 |
| child 153 | 73402d5b778e |
| permissions | -rw-r--r-- |
| 3 | 1 |
#ifndef GAMESTATE_HH |
2 |
#define GAMESTATE_HH |
|
3 |
||
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
4 |
#include "Physics.hh" |
|
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
5 |
#include "Input.hh" |
|
136
3a15a5937f7a
Moved constants to one header Config.hh, we probably should use somekind of resourcemanager. But do we have time for that? :)
saiam
parents:
127
diff
changeset
|
6 |
#include "Config.hh" |
|
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
7 |
|
| 5 | 8 |
#include <list> |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
9 |
#include <stdexcept> |
| 108 | 10 |
#include <cmath> |
11 |
||
| 26 | 12 |
// forward-declare GameState |
13 |
class GameState; |
|
14 |
||
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
15 |
class Player : public PhysicsObject {
|
| 108 | 16 |
protected: |
17 |
GameState &state; |
|
18 |
bool visible; |
|
19 |
||
20 |
public: |
|
21 |
Player(GameState &state, Vector position, bool visible) : |
|
22 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
|
|
23 |
||
24 |
std::vector<Vector> shape(4); |
|
25 |
shape[0] = Vector(0,-18); |
|
26 |
shape[1] = Vector(6,-9); |
|
27 |
shape[2] = Vector(0,0); |
|
28 |
shape[3] = Vector(-6,-9); |
|
29 |
// Initialize the shape of the player (salmiakki shape) |
|
30 |
setShape(shape); |
|
31 |
} |
|
32 |
||
33 |
void debugInfo (); |
|
34 |
||
35 |
public: |
|
36 |
virtual void handleMove (PlayerInput_Move input); |
|
37 |
||
| 3 | 38 |
|
39 |
}; |
|
40 |
||
| 116 | 41 |
class Shot : public PhysicsObject {
|
42 |
protected: |
|
43 |
GameState &state; |
|
44 |
bool visible; |
|
45 |
uint32_t birth_tick; |
|
46 |
uint32_t death_tick; |
|
47 |
public: |
|
48 |
Shot(GameState &state, Vector position, bool visible) : |
|
49 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
|
|
|
127
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
50 |
// Looks kind of dumb, for ammunition to have shape |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
51 |
std::vector<Vector> shape(4); |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
52 |
shape[0] = Vector(-1, -1); |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
53 |
shape[1] = Vector(-1, 1); |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
54 |
shape[2] = Vector(1, 1); |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
55 |
shape[3] = Vector(1, -1); |
|
241830182118
added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents:
126
diff
changeset
|
56 |
setShape(shape); |
| 116 | 57 |
} |
58 |
private: |
|
59 |
virtual void onCollision(); |
|
60 |
}; |
|
61 |
||
| 3 | 62 |
class LocalPlayer : public Player {
|
| 108 | 63 |
protected: |
64 |
LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
|
|
| 3 | 65 |
}; |
66 |
||
67 |
class RemotePlayer : public Player {
|
|
| 108 | 68 |
protected: |
69 |
RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
|
|
| 6 | 70 |
}; |
71 |
||
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
72 |
class GameState : public PhysicsWorld {
|
| 108 | 73 |
public: |
74 |
std::list<Player*> player_list; |
|
| 8 | 75 |
|
| 108 | 76 |
// only one local player is supported |
77 |
LocalPlayer *local_player; |
|
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
78 |
|
| 108 | 79 |
GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) {
|
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
80 |
|
| 108 | 81 |
} |
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
82 |
|
| 108 | 83 |
/* |
84 |
* This will return NULL if we don't have a local player - yet |
|
85 |
*/ |
|
86 |
LocalPlayer *getLocalPlayer (void) {
|
|
87 |
return local_player; |
|
88 |
} |
|
| 24 | 89 |
|
| 108 | 90 |
void newLocalPlayer (LocalPlayer *player) {
|
91 |
if (local_player) |
|
92 |
throw std::logic_error("newLocalPlayer called even though we already have a local player");
|
|
| 24 | 93 |
|
| 108 | 94 |
player_list.push_back(player); |
| 24 | 95 |
|
| 108 | 96 |
local_player = player; |
97 |
} |
|
| 24 | 98 |
|
| 108 | 99 |
void newRemotePlayer (RemotePlayer *player) {
|
100 |
player_list.push_back(player); |
|
101 |
} |
|
102 |
||
103 |
void removePlayer (Player *player) {
|
|
104 |
player_list.remove(player); |
|
105 |
} |
|
| 6 | 106 |
}; |
107 |
||
| 3 | 108 |
#endif |