author | nireco |
Fri, 28 Nov 2008 13:11:51 +0000 | |
changeset 116 | 0d36aade845e |
parent 115 | 237ea0bb125a |
child 126 | 7885c71653d0 |
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; |
115
237ea0bb125a
Kirjottelin jotain uuden t?rm?ystarkistuksen tapasta, se kyll? bugaa jotenkin.
saiam
parents:
108
diff
changeset
|
17 |
const float COLLISION_ELASTICITY = 0.4; |
237ea0bb125a
Kirjottelin jotain uuden t?rm?ystarkistuksen tapasta, se kyll? bugaa jotenkin.
saiam
parents:
108
diff
changeset
|
18 |
|
60 | 19 |
const float PLAYER_MASS = 10.0; |
79 | 20 |
const float PLAYER_MOVE_FORCE = 5000.0; |
21 |
const float PLAYER_INITIAL_X = 400.0; |
|
22 |
const float PLAYER_INITIAL_Y = 300.0; |
|
115
237ea0bb125a
Kirjottelin jotain uuden t?rm?ystarkistuksen tapasta, se kyll? bugaa jotenkin.
saiam
parents:
108
diff
changeset
|
23 |
const float PLAYER_MIN_SPEED = 10.0; |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
24 |
|
108 | 25 |
const float CROSSHAIR_ANGLE_SPEED = PI/40; // TODO: Adjust this |
26 |
const float PLAYER_AIM_MIN = -KG_PI/2; // TODO: -- || -- |
|
27 |
const float PLAYER_AIM_MAX = KG_PI/2; // TODO: -- || -- |
|
28 |
||
26 | 29 |
// forward-declare GameState |
30 |
class GameState; |
|
31 |
||
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
32 |
class Player : public PhysicsObject { |
108 | 33 |
protected: |
34 |
GameState &state; |
|
35 |
bool visible; |
|
36 |
||
37 |
public: |
|
38 |
Player(GameState &state, Vector position, bool visible) : |
|
39 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { |
|
40 |
||
41 |
std::vector<Vector> shape(4); |
|
42 |
shape[0] = Vector(0,-18); |
|
43 |
shape[1] = Vector(6,-9); |
|
44 |
shape[2] = Vector(0,0); |
|
45 |
shape[3] = Vector(-6,-9); |
|
46 |
// Initialize the shape of the player (salmiakki shape) |
|
47 |
setShape(shape); |
|
48 |
} |
|
49 |
||
50 |
void debugInfo (); |
|
51 |
||
52 |
public: |
|
53 |
virtual void handleMove (PlayerInput_Move input); |
|
54 |
||
3 | 55 |
|
56 |
}; |
|
57 |
||
116 | 58 |
class Shot : public PhysicsObject { |
59 |
protected: |
|
60 |
GameState &state; |
|
61 |
bool visible; |
|
62 |
uint32_t birth_tick; |
|
63 |
uint32_t death_tick; |
|
64 |
public: |
|
65 |
Shot(GameState &state, Vector position, bool visible) : |
|
66 |
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { |
|
67 |
||
68 |
} |
|
69 |
private: |
|
70 |
virtual void onCollision(); |
|
71 |
}; |
|
72 |
||
3 | 73 |
class LocalPlayer : public Player { |
108 | 74 |
protected: |
75 |
LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } |
|
3 | 76 |
}; |
77 |
||
78 |
class RemotePlayer : public Player { |
|
108 | 79 |
protected: |
80 |
RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { } |
|
6 | 81 |
}; |
82 |
||
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
83 |
class GameState : public PhysicsWorld { |
108 | 84 |
public: |
85 |
std::list<Player*> player_list; |
|
8 | 86 |
|
108 | 87 |
// only one local player is supported |
88 |
LocalPlayer *local_player; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
89 |
|
108 | 90 |
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
|
91 |
|
108 | 92 |
} |
42
eb1a93a38cde
lazy commit that breaks everything, should be a branch
terom
parents:
26
diff
changeset
|
93 |
|
108 | 94 |
/* |
95 |
* This will return NULL if we don't have a local player - yet |
|
96 |
*/ |
|
97 |
LocalPlayer *getLocalPlayer (void) { |
|
98 |
return local_player; |
|
99 |
} |
|
24 | 100 |
|
108 | 101 |
void newLocalPlayer (LocalPlayer *player) { |
102 |
if (local_player) |
|
103 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
|
24 | 104 |
|
108 | 105 |
player_list.push_back(player); |
24 | 106 |
|
108 | 107 |
local_player = player; |
108 |
} |
|
24 | 109 |
|
108 | 110 |
void newRemotePlayer (RemotePlayer *player) { |
111 |
player_list.push_back(player); |
|
112 |
} |
|
113 |
||
114 |
void removePlayer (Player *player) { |
|
115 |
player_list.remove(player); |
|
116 |
} |
|
6 | 117 |
}; |
118 |
||
3 | 119 |
#endif |