src/proto2/GameState.hh
author terom
Tue, 18 Nov 2008 18:50:32 +0000
changeset 50 9e1a6506f5a1
parent 42 eb1a93a38cde
child 58 a53f5ad69500
permissions -rw-r--r--
some rough-handed code modifications towards a newer, better, working Physics
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
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    10
const uint16_t PLAYER_MASS = 8035;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    11
const uint16_t PLAYER_DIM_W = 10;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    12
const uint16_t PLAYER_DIM_H = 10;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    13
const uint16_t MAP_DIM_W = 800;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    14
const uint16_t MAP_DIM_H = 640;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    15
26
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    16
// forward-declare GameState
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    17
class GameState;
5685602aeb9c it works \o/
terom
parents: 25
diff changeset
    18
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    19
class Player : public PhysicsObject {
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    20
    protected:
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    21
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    22
    public:
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    23
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    24
        Player(Vector position, bool visible) : 
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    25
            PhysicsObject(PLAYER_MASS, position, Vector(0, 0), Vector(0, 0)), visible(visible) { }
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    26
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    27
        bool visible;
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    28
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    29
5a209a8585c9 proto p2
terom
parents:
diff changeset
    30
class LocalPlayer : public Player {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    31
    protected:
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    32
        LocalPlayer (Vector pos, bool visible) : Player(pos, visible) { }
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    33
    
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    34
    public:
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    35
        virtual bool handleMove (PlayerInput_Move input);
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    36
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    37
5a209a8585c9 proto p2
terom
parents:
diff changeset
    38
class RemotePlayer : public Player {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    39
    protected:
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    40
        RemotePlayer (Vector pos, bool visible) : Player(pos, visible) { }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    41
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    42
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    43
class GameState : public PhysicsWorld {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    44
    public:
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    45
        std::list<Player*> player_list;
8
2de58a6d0395 fix to mostly compile
terom
parents: 6
diff changeset
    46
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    47
        // only one local player is supported
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    48
        LocalPlayer *local_player;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    49
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 42
diff changeset
    50
        GameState (void) : PhysicsWorld(Vector(MAP_DIM_W, MAP_DIM_H)), local_player(NULL) {
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 8
diff changeset
    51
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    52
        }
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents: 26
diff changeset
    53
       
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    54
        /*
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    55
         * This will return NULL if we don't have a local player - yet
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    56
         */
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    57
        LocalPlayer *getLocalPlayer (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    58
            return local_player;
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    59
        }
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    60
        
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    61
        void newLocalPlayer (LocalPlayer *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    62
            if (local_player)
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    63
                throw std::logic_error("newLocalPlayer called even though we already have a local player");
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    64
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    65
            player_list.push_back(player);
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    66
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    67
            local_player = player;
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    68
        }
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    69
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    70
        void newRemotePlayer (RemotePlayer *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    71
            player_list.push_back(player);
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 removePlayer (Player *player) {
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    75
            player_list.remove(player);
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    76
        }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    77
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    78
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    79
#endif