author | terom |
Tue, 18 Nov 2008 22:58:50 +0000 | |
branch | no-netsession |
changeset 35 | e21cfda0edde |
parent 26 | 5685602aeb9c |
child 41 | ca80cd67785d |
permissions | -rw-r--r-- |
3 | 1 |
#ifndef GAMESTATE_HH |
2 |
#define GAMESTATE_HH |
|
3 |
||
35 | 4 |
#include "Physics.hh" |
5 |
#include "Input.hh" |
|
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
6 |
|
5 | 7 |
#include <list> |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
8 |
#include <stdexcept> |
5 | 9 |
|
35 | 10 |
// in meters/kg |
11 |
const float MAP_WIDTH = 100.0; |
|
12 |
const float MAP_HEIGHT = 100.0; |
|
13 |
const float MAP_GRAVITY = 9.81; |
|
14 |
const float PLAYER_MASS = 10.0; |
|
15 |
const float PLAYER_MOVE_FORCE = 500.0; |
|
16 |
const float PLAYER_INITIAL_X = 50.0; |
|
17 |
const float PLAYER_INITIAL_Y = 40.0; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
18 |
|
26 | 19 |
// forward-declare GameState |
20 |
class GameState; |
|
21 |
||
35 | 22 |
class Player : public PhysicsObject { |
24 | 23 |
protected: |
26 | 24 |
GameState &state; |
35 | 25 |
bool visible; |
26 | 26 |
|
24 | 27 |
public: |
3 | 28 |
|
35 | 29 |
Player(GameState &state, Vector position, bool visible) : |
30 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { } |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
31 |
|
3 | 32 |
}; |
33 |
||
34 |
class LocalPlayer : public Player { |
|
24 | 35 |
protected: |
35 | 36 |
LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } |
24 | 37 |
|
38 |
public: |
|
35 | 39 |
virtual void handleMove (PlayerInput_Move input); |
3 | 40 |
}; |
41 |
||
42 |
class RemotePlayer : public Player { |
|
24 | 43 |
protected: |
35 | 44 |
RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } |
6 | 45 |
}; |
46 |
||
35 | 47 |
class GameState : public PhysicsWorld { |
24 | 48 |
public: |
49 |
std::list<Player*> player_list; |
|
8 | 50 |
|
24 | 51 |
// only one local player is supported |
52 |
LocalPlayer *local_player; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
53 |
|
35 | 54 |
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
|
55 |
|
24 | 56 |
} |
35 | 57 |
|
25 | 58 |
/* |
59 |
* This will return NULL if we don't have a local player - yet |
|
60 |
*/ |
|
61 |
LocalPlayer *getLocalPlayer (void) { |
|
62 |
return local_player; |
|
24 | 63 |
} |
64 |
||
65 |
void newLocalPlayer (LocalPlayer *player) { |
|
66 |
if (local_player) |
|
67 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
|
68 |
||
69 |
player_list.push_back(player); |
|
70 |
||
71 |
local_player = player; |
|
72 |
} |
|
73 |
||
74 |
void newRemotePlayer (RemotePlayer *player) { |
|
75 |
player_list.push_back(player); |
|
76 |
} |
|
77 |
||
78 |
void removePlayer (Player *player) { |
|
79 |
player_list.remove(player); |
|
80 |
} |
|
6 | 81 |
}; |
82 |
||
3 | 83 |
#endif |