author | Tero Marttila <terom@fixme.fi> |
Tue, 13 Jan 2009 23:15:47 +0200 | |
changeset 393 | 5dd4d782cf3a |
parent 282 | e0e4dfc3e528 |
child 408 | e6cfc44266af |
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) : |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
7 |
world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL), event_handler(NULL) |
255
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 |
} |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
11 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
12 |
void GameState::setEventHandler (GameStateEventHandler *handler) { |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
13 |
if (handler && event_handler != NULL) |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
14 |
throw Error("event_handler already set"); |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
15 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
16 |
event_handler = handler; |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
17 |
} |
199 | 18 |
|
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
|
19 |
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
|
20 |
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
|
21 |
} |
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
|
22 |
|
199 | 23 |
LocalPlayer *GameState::getLocalPlayer (void) { |
24 |
return local_player; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
25 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
266
diff
changeset
|
27 |
void GameState::setLocalPlayer (LocalPlayer *player) { |
199 | 28 |
if (local_player) |
29 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
|
30 |
||
31 |
local_player = player; |
|
32 |
} |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
199
diff
changeset
|
33 |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
266
diff
changeset
|
34 |
void GameState::addPlayer (Player *player) { |
199 | 35 |
player_list.push_back(player); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
36 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
37 |
if (event_handler) |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
38 |
event_handler->on_player_joined(player); |
199 | 39 |
} |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
40 |
|
199 | 41 |
void GameState::removePlayer (Player *player) { |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
266
diff
changeset
|
42 |
if (player == local_player) |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
266
diff
changeset
|
43 |
local_player = NULL; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
266
diff
changeset
|
44 |
|
199 | 45 |
player_list.remove(player); |
393
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
46 |
|
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
47 |
if (event_handler) |
5dd4d782cf3a
a basic implementation of game messages, plus some weird GameStateEvent stuff
Tero Marttila <terom@fixme.fi>
parents:
282
diff
changeset
|
48 |
event_handler->on_player_left(player); |
199 | 49 |
} |
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 |
|
266
ad72d0a0cc02
increase the map size and control the camera to always have the screen full of terrain
terom
parents:
263
diff
changeset
|
51 |
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
|
52 |
// 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
|
53 |
world.draw(g, camera); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
|
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
|
55 |
// 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
|
56 |
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
|
57 |
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
|
58 |
|
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
|
59 |
// 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
|
60 |
if (p == local_player) |
248 | 61 |
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
|
62 |
else |
248 | 63 |
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
|
64 |
} |
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
|
65 |
|
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
|
66 |
// 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
|
67 |
for (std::list<Projectile*>::iterator it = projectiles.begin(); it != projectiles.end(); it++) { |
248 | 68 |
(*it)->draw(g, camera); |
225 | 69 |
} |
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
|
70 |
} |
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
|
71 |