author | terom |
Sun, 07 Dec 2008 21:58:34 +0000 | |
changeset 266 | ad72d0a0cc02 |
parent 263 | 8c999cf4c182 |
child 274 | c35307e8645c |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#include "GameState.hh" |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
#include "Engine.hh" |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
4 |
#include "Config.hh" |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
5 |
|
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
6 |
GameState::GameState (void) : |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
7 |
local_player(NULL), world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)) |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
8 |
{ |
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
9 |
|
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
10 |
} |
199 | 11 |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
12 |
void GameState::addProjectile (Projectile *projectile) { |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
13 |
projectiles.push_back(projectile); |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
14 |
} |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
15 |
|
199 | 16 |
LocalPlayer *GameState::getLocalPlayer (void) { |
17 |
return local_player; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
|
199 | 20 |
void GameState::newLocalPlayer (LocalPlayer *player) { |
21 |
if (local_player) |
|
22 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
|
23 |
||
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
200
diff
changeset
|
24 |
newPlayer(player); |
199 | 25 |
|
26 |
local_player = player; |
|
27 |
} |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
199
diff
changeset
|
28 |
|
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
200
diff
changeset
|
29 |
void GameState::newPlayer (Player *player) { |
199 | 30 |
player_list.push_back(player); |
31 |
} |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
32 |
|
199 | 33 |
void GameState::removePlayer (Player *player) { |
34 |
player_list.remove(player); |
|
35 |
} |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
36 |
|
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
263
diff
changeset
|
37 |
void GameState::draw(Graphics *g, PixelCoordinate camera, bool displayWeapon) { |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
38 |
// Draw world/terrain |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
248
diff
changeset
|
39 |
world.draw(g, camera); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
40 |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
41 |
// Draw players |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
42 |
for (std::list<Player*>::iterator it = player_list.begin(); it != player_list.end(); it++) { |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
43 |
Player *p = *it; |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
44 |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
45 |
// our LocalPlayer has it's own draw method |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
46 |
if (p == local_player) |
248 | 47 |
local_player->draw(g, displayWeapon, camera); |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
48 |
else |
248 | 49 |
p->draw(g, camera); |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
50 |
} |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
225
diff
changeset
|
51 |
|
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
52 |
// Draw projectiles |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
53 |
for (std::list<Projectile*>::iterator it = projectiles.begin(); it != projectiles.end(); it++) { |
248 | 54 |
(*it)->draw(g, camera); |
225 | 55 |
} |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
56 |
} |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
209
diff
changeset
|
57 |