author | terom |
Tue, 18 Nov 2008 18:50:32 +0000 | |
changeset 50 | 9e1a6506f5a1 |
parent 42 | eb1a93a38cde |
child 58 | a53f5ad69500 |
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" |
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 |
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
10 |
const uint16_t PLAYER_MASS = 8035; |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
11 |
const uint16_t PLAYER_DIM_W = 10; |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
12 |
const uint16_t PLAYER_DIM_H = 10; |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
13 |
const uint16_t MAP_DIM_W = 800; |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
14 |
const uint16_t MAP_DIM_H = 640; |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
15 |
|
26 | 16 |
// forward-declare GameState |
17 |
class GameState; |
|
18 |
||
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
19 |
class Player : public PhysicsObject { |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
20 |
protected: |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
21 |
|
24 | 22 |
public: |
3 | 23 |
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
24 |
Player(Vector position, bool visible) : |
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
25 |
PhysicsObject(PLAYER_MASS, position, Vector(0, 0), Vector(0, 0)), visible(visible) { } |
24 | 26 |
|
27 |
bool visible; |
|
3 | 28 |
}; |
29 |
||
30 |
class LocalPlayer : public Player { |
|
24 | 31 |
protected: |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
32 |
LocalPlayer (Vector pos, bool visible) : Player(pos, visible) { } |
24 | 33 |
|
34 |
public: |
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
35 |
virtual bool handleMove (PlayerInput_Move input); |
3 | 36 |
}; |
37 |
||
38 |
class RemotePlayer : public Player { |
|
24 | 39 |
protected: |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
40 |
RemotePlayer (Vector pos, bool visible) : Player(pos, visible) { } |
6 | 41 |
}; |
42 |
||
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
43 |
class GameState : public PhysicsWorld { |
24 | 44 |
public: |
45 |
std::list<Player*> player_list; |
|
8 | 46 |
|
24 | 47 |
// only one local player is supported |
48 |
LocalPlayer *local_player; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
49 |
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
50 |
GameState (void) : PhysicsWorld(Vector(MAP_DIM_W, MAP_DIM_H)), local_player(NULL) { |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
51 |
|
24 | 52 |
} |
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
53 |
|
25 | 54 |
/* |
55 |
* This will return NULL if we don't have a local player - yet |
|
56 |
*/ |
|
57 |
LocalPlayer *getLocalPlayer (void) { |
|
58 |
return local_player; |
|
24 | 59 |
} |
60 |
||
61 |
void newLocalPlayer (LocalPlayer *player) { |
|
62 |
if (local_player) |
|
63 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
|
64 |
||
65 |
player_list.push_back(player); |
|
66 |
||
67 |
local_player = player; |
|
68 |
} |
|
69 |
||
70 |
void newRemotePlayer (RemotePlayer *player) { |
|
71 |
player_list.push_back(player); |
|
72 |
} |
|
73 |
||
74 |
void removePlayer (Player *player) { |
|
75 |
player_list.remove(player); |
|
76 |
} |
|
6 | 77 |
}; |
78 |
||
3 | 79 |
#endif |