| author | nireco |
| Mon, 24 Nov 2008 21:38:04 +0000 | |
| changeset 101 | 1c52bd7fbc43 |
| parent 96 | 4a801210096c |
| child 108 | 1b93045a5b0a |
| 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 |
|
| 79 | 10 |
// in cells/kg |
11 |
const uint16_t MAP_WIDTH = 800; |
|
12 |
const uint16_t MAP_HEIGHT = 600; |
|
| 88 | 13 |
const float MAP_GRAVITY = 1200.0; |
| 60 | 14 |
const float PLAYER_MASS = 10.0; |
| 79 | 15 |
const float PLAYER_MOVE_FORCE = 5000.0; |
16 |
const float PLAYER_INITIAL_X = 400.0; |
|
17 |
const float PLAYER_INITIAL_Y = 300.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 |
||
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
22 |
class Player : public PhysicsObject {
|
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
23 |
protected: |
| 60 | 24 |
GameState &state; |
25 |
bool visible; |
|
|
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
42
diff
changeset
|
26 |
|
| 24 | 27 |
public: |
| 91 | 28 |
Player(GameState &state, Vector position, bool visible) : |
29 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
|
|
| 3 | 30 |
|
| 91 | 31 |
std::vector<Vector> shape(4); |
| 94 | 32 |
shape[0] = Vector(0,-18); |
33 |
shape[1] = Vector(6,-9); |
|
34 |
shape[2] = Vector(0,0); |
|
35 |
shape[3] = Vector(-6,-9); |
|
| 91 | 36 |
// Initialize the shape of the player (salmiakki shape) |
37 |
setShape(shape); |
|
38 |
} |
|
| 24 | 39 |
|
| 94 | 40 |
void debugInfo (); |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
41 |
|
|
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
42 |
public: |
|
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
43 |
virtual void handleMove (PlayerInput_Move input); |
| 3 | 44 |
}; |
45 |
||
46 |
class LocalPlayer : public Player {
|
|
| 24 | 47 |
protected: |
| 60 | 48 |
LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
|
| 3 | 49 |
}; |
50 |
||
51 |
class RemotePlayer : public Player {
|
|
| 24 | 52 |
protected: |
| 60 | 53 |
RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
|
| 6 | 54 |
}; |
55 |
||
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
56 |
class GameState : public PhysicsWorld {
|
| 24 | 57 |
public: |
58 |
std::list<Player*> player_list; |
|
| 8 | 59 |
|
| 24 | 60 |
// only one local player is supported |
61 |
LocalPlayer *local_player; |
|
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
62 |
|
| 60 | 63 |
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
|
64 |
|
| 24 | 65 |
} |
|
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
66 |
|
| 25 | 67 |
/* |
68 |
* This will return NULL if we don't have a local player - yet |
|
69 |
*/ |
|
70 |
LocalPlayer *getLocalPlayer (void) {
|
|
71 |
return local_player; |
|
| 24 | 72 |
} |
73 |
||
74 |
void newLocalPlayer (LocalPlayer *player) {
|
|
75 |
if (local_player) |
|
76 |
throw std::logic_error("newLocalPlayer called even though we already have a local player");
|
|
77 |
||
78 |
player_list.push_back(player); |
|
79 |
||
80 |
local_player = player; |
|
81 |
} |
|
82 |
||
83 |
void newRemotePlayer (RemotePlayer *player) {
|
|
84 |
player_list.push_back(player); |
|
85 |
} |
|
86 |
||
87 |
void removePlayer (Player *player) {
|
|
88 |
player_list.remove(player); |
|
89 |
} |
|
| 6 | 90 |
}; |
91 |
||
| 3 | 92 |
#endif |