src/proto2/GameState.hh
author ekku
Sun, 23 Nov 2008 18:19:53 +0000
changeset 94 08bebac3d0c2
parent 92 fe9da348afed
child 96 4a801210096c
permissions -rw-r--r--
Maalla liikkumista
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>
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents: 4
diff changeset
     9
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    10
// in cells/kg
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    11
const uint16_t MAP_WIDTH = 800;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    12
const uint16_t MAP_HEIGHT = 600;
88
7431cd0cf900 Kuu n?kyy!
ekku
parents: 79
diff changeset
    13
const float MAP_GRAVITY = 1200.0;
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    14
const float PLAYER_MASS = 10.0;
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    15
const float PLAYER_MOVE_FORCE = 5000.0;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    16
const float PLAYER_INITIAL_X = 400.0;
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 68
diff changeset
    17
const float PLAYER_INITIAL_Y = 300.0;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    18
26
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    19
// forward-declare GameState
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    20
class GameState;
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    21
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    22
class Player : public PhysicsObject {
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    23
    protected:
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    24
        GameState &state;
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    25
        bool visible;
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    26
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    27
    public:
91
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    28
        Player(GameState &state, Vector position, bool visible) : 
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    29
            PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    30
91
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    31
			std::vector<Vector> shape(4);
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 92
diff changeset
    32
			shape[0] = Vector(0,-18);
08bebac3d0c2 Maalla liikkumista
ekku
parents: 92
diff changeset
    33
			shape[1] = Vector(6,-9);
08bebac3d0c2 Maalla liikkumista
ekku
parents: 92
diff changeset
    34
			shape[2] = Vector(0,0); 
08bebac3d0c2 Maalla liikkumista
ekku
parents: 92
diff changeset
    35
			shape[3] = Vector(-6,-9);
91
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    36
			// Initialize the shape of the player (salmiakki shape)
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    37
			setShape(shape);		
0a6d675099dc Mato salmiakin muotoiseksi
ekku
parents: 88
diff changeset
    38
		}
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    39
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 92
diff changeset
    40
		void debugInfo ();
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    41
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    42
5a209a8585c9 proto p2
terom
parents:
diff changeset
    43
class LocalPlayer : public Player {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    44
    protected:
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    45
        LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    46
    
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    47
    public:
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    48
        virtual void handleMove (PlayerInput_Move input);
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    49
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    50
5a209a8585c9 proto p2
terom
parents:
diff changeset
    51
class RemotePlayer : public Player {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    52
    protected:
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    53
        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
    54
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    55
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    56
class GameState : public PhysicsWorld {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    57
    public:
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    58
        std::list<Player*> player_list;
8
2de58a6d0395 fix to mostly compile
terom
parents: 6
diff changeset
    59
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    60
        // only one local player is supported
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    61
        LocalPlayer *local_player;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    62
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    63
        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
    64
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    65
        }
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    66
       
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    67
        /*
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    68
         * This will return NULL if we don't have a local player - yet
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    69
         */
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    70
        LocalPlayer *getLocalPlayer (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    71
            return local_player;
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    72
        }
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    73
        
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    74
        void newLocalPlayer (LocalPlayer *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    75
            if (local_player)
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    76
                throw std::logic_error("newLocalPlayer called even though we already have a local player");
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    77
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    78
            player_list.push_back(player);
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    79
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    80
            local_player = player;
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    81
        }
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    82
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    83
        void newRemotePlayer (RemotePlayer *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    84
            player_list.push_back(player);
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    85
        }
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    86
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    87
        void removePlayer (Player *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    88
            player_list.remove(player);
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    89
        }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    90
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    91
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    92
#endif