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