src/proto2/GameState.hh
author saiam
Sat, 29 Nov 2008 17:29:53 +0000
changeset 133 c05e84ccc4b3
parent 127 241830182118
child 136 3a15a5937f7a
permissions -rw-r--r--
Made unnecessarily virtual function PhysicsObject::applyForce nonvirtual
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
     1
#ifndef GAMESTATE_HH
5a209a8585c9 proto p2
terom
parents:
diff changeset
     2
#define GAMESTATE_HH
5a209a8585c9 proto p2
terom
parents:
diff changeset
     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
617813994ab1 move proto/p2 -> src/proto2
terom
parents: 4
diff changeset
     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
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
     9
#include <cmath>
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    10
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    11
const float KG_PI = 3.14159265;
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents: 4
diff changeset
    12
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    13
// in cells/kg
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    14
const uint16_t MAP_WIDTH = 800;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    15
const uint16_t MAP_HEIGHT = 600;
88
7431cd0cf900 Kuu n?kyy!
ekku
parents: 79
diff changeset
    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
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    19
const float PLAYER_MASS = 10.0;
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    20
const float PLAYER_MOVE_FORCE = 5000.0;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    21
const float PLAYER_INITIAL_X = 400.0;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    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
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    25
const float CROSSHAIR_ANGLE_SPEED = PI/40; // TODO: Adjust this
126
7885c71653d0 restricted targeting down to 45 degrees
nireco
parents: 116
diff changeset
    26
const float PLAYER_AIM_MIN = -KG_PI/4; // TODO: -- || --
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    27
const float PLAYER_AIM_MAX = KG_PI/2; // TODO: -- || --
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    28
26
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    29
// forward-declare GameState
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    30
class GameState;
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    31
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    32
class Player : public PhysicsObject {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    33
protected:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    34
    GameState &state;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    35
    bool visible;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    36
    
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    37
public:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    38
    Player(GameState &state, Vector position, bool visible) : 
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    39
        PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    40
            
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    41
        std::vector<Vector> shape(4);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    42
        shape[0] = Vector(0,-18);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    43
        shape[1] = Vector(6,-9);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    44
        shape[2] = Vector(0,0); 
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    45
        shape[3] = Vector(-6,-9);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    46
        // Initialize the shape of the player (salmiakki shape)
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    47
        setShape(shape);		
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    48
    }
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    49
    
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    50
    void debugInfo ();
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    51
    
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    52
public:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    53
    virtual void handleMove (PlayerInput_Move input);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    54
    
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    55
5a209a8585c9 proto p2
terom
parents:
diff changeset
    56
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    57
116
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    58
class Shot : public PhysicsObject {
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    59
protected:
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    60
    GameState &state;
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    61
    bool visible;
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    62
    uint32_t birth_tick;
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    63
    uint32_t death_tick;
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    64
public:
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    65
    Shot(GameState &state, Vector position, bool visible) :
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    66
        PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
127
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    67
        // Looks kind of dumb, for ammunition to have shape
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    68
        std::vector<Vector> shape(4);
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    69
        shape[0] = Vector(-1, -1);
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    70
        shape[1] = Vector(-1, 1);
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    71
        shape[2] = Vector(1, 1);
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    72
        shape[3] = Vector(1, -1);
241830182118 added shape to Shot, shouldn't need it, but drawing might need it. Well Shot is not used anywhere at the moment
nireco
parents: 126
diff changeset
    73
        setShape(shape);
116
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    74
    }
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    75
private:
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    76
    virtual void onCollision();
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    77
};
0d36aade845e some stuff, don't remember what
nireco
parents: 115
diff changeset
    78
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    79
class LocalPlayer : public Player {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    80
protected:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    81
    LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    82
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    83
5a209a8585c9 proto p2
terom
parents:
diff changeset
    84
class RemotePlayer : public Player {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    85
protected:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    86
    RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    87
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    88
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    89
class GameState : public PhysicsWorld {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    90
public:
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    91
    std::list<Player*> player_list;
8
2de58a6d0395 fix to mostly compile
terom
parents: 6
diff changeset
    92
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    93
    // only one local player is supported
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    94
    LocalPlayer *local_player;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    95
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    96
    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
    97
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    98
    }
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    99
       
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   100
    /*
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   101
     * This will return NULL if we don't have a local player - yet
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   102
     */
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   103
    LocalPlayer *getLocalPlayer (void) {
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   104
        return local_player;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   105
    }
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
   106
        
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   107
    void newLocalPlayer (LocalPlayer *player) {
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   108
        if (local_player)
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   109
            throw std::logic_error("newLocalPlayer called even though we already have a local player");
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
   110
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   111
        player_list.push_back(player);
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
   112
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   113
        local_player = player;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   114
    }
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
   115
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   116
    void newRemotePlayer (RemotePlayer *player) {
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   117
        player_list.push_back(player);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   118
    }
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   119
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   120
    void removePlayer (Player *player) {
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   121
        player_list.remove(player);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
   122
    }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
   123
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
   124
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
   125
#endif