src/GameState.cc
author terom
Tue, 09 Dec 2008 04:41:48 +0000
changeset 368 fe49a4b12575
parent 282 e0e4dfc3e528
child 393 5dd4d782cf3a
permissions -rw-r--r--
move our overdrive-doxygen stuff to doxygen_hc_overclock.cfg
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) : 
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 274
diff changeset
     7
    world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(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
}
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    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
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    16
LocalPlayer *GameState::getLocalPlayer (void) {
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    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
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 266
diff changeset
    20
void GameState::setLocalPlayer (LocalPlayer *player) {
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    21
    if (local_player)
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    22
        throw std::logic_error("newLocalPlayer called even though we already have a local player");
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    23
    
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    24
    local_player = player;
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    25
}
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 199
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::addPlayer (Player *player) {
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    28
    player_list.push_back(player);
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    29
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    30
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    31
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
    32
    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
    33
        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
    34
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    35
    player_list.remove(player);
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 196
diff changeset
    36
}
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
    37
    
266
ad72d0a0cc02 increase the map size and control the camera to always have the screen full of terrain
terom
parents: 263
diff changeset
    38
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
    39
    // 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
    40
    world.draw(g, camera);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    41
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
    42
    // 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
    43
    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
    44
        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
    45
        
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
        // 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
    47
        if (p == local_player)
248
e40ef56dc62c scrolling looks like it works
nireco
parents: 233
diff changeset
    48
            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
    49
        else
248
e40ef56dc62c scrolling looks like it works
nireco
parents: 233
diff changeset
    50
            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
    51
    }
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
    52
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
    53
    // 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
    54
    for (std::list<Projectile*>::iterator it = projectiles.begin(); it != projectiles.end(); it++) {
248
e40ef56dc62c scrolling looks like it works
nireco
parents: 233
diff changeset
    55
        (*it)->draw(g, camera);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    56
    }
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
    57
}
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
    58