src/proto2/GameState.cc
author saiam
Fri, 28 Nov 2008 22:26:23 +0000
changeset 128 890ac82cdcc0
parent 122 16a73ebca810
child 153 73402d5b778e
permissions -rw-r--r--
Documenting more, cleaning variables. This code needs some serious
rewriting. (And we havent too many features either)
26
5685602aeb9c it works \o/
terom
parents:
diff changeset
     1
5685602aeb9c it works \o/
terom
parents:
diff changeset
     2
#include "GameState.hh"
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 66
diff changeset
     3
#include "Engine.hh"
26
5685602aeb9c it works \o/
terom
parents:
diff changeset
     4
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 94
diff changeset
     5
void Player::handleMove (PlayerInput_Move input) {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
     6
    float fx = 0; // Force in x-direction
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
     7
    float da = 0; // Crosshair angle
26
5685602aeb9c it works \o/
terom
parents:
diff changeset
     8
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 94
diff changeset
     9
    // handle left/right
54
b8b043ba0abd fix some more compiler errors...
terom
parents: 50
diff changeset
    10
    if (input & INPUT_MOVE_LEFT)
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    11
        fx -= PLAYER_MOVE_FORCE;
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 26
diff changeset
    12
54
b8b043ba0abd fix some more compiler errors...
terom
parents: 50
diff changeset
    13
    if (input & INPUT_MOVE_RIGHT)
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    14
        fx += PLAYER_MOVE_FORCE;
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 66
diff changeset
    15
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    16
    if (input & INPUT_MOVE_UP)
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    17
        da += CROSSHAIR_ANGLE_SPEED;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    18
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    19
    if (input & INPUT_MOVE_DOWN)
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    20
        da -= CROSSHAIR_ANGLE_SPEED;
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    21
114
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    22
    if (input & INPUT_MOVE_JUMP)
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    23
        jump();
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    24
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    25
    this->changeAim(da); // Move crosshair
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    26
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    27
    // Player facing
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    28
    if (fx < 0) setFacing(false);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    29
    else if (fx > 0) setFacing(true);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    30
114
71f7e9d3d052 V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents: 108
diff changeset
    31
    // Apply force
122
16a73ebca810 No warnings anymore, but well have to think about that applyForce
saiam
parents: 117
diff changeset
    32
    applyForce(Vector(fx, 0));
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    33
117
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    34
    // dig/shoot or something
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    35
    if (input & INPUT_MOVE_DIG) {
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    36
        // Should create Shot which destroys ground, but also should be destroyed then,
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    37
        // but it doesn't.
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    38
        // But this now just segfaults
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    39
//        world.addObject(new Shot(state, position, true));
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    40
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    41
        world.removeGround(position, 10);
2877eef6c1d5 digging
nireco
parents: 116
diff changeset
    42
    }
26
5685602aeb9c it works \o/
terom
parents:
diff changeset
    43
}
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 66
diff changeset
    44
08bebac3d0c2 Maalla liikkumista
ekku
parents: 66
diff changeset
    45
void Player::debugInfo (void) {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    46
    Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir;
94
08bebac3d0c2 Maalla liikkumista
ekku
parents: 66
diff changeset
    47
}
116
0d36aade845e some stuff, don't remember what
nireco
parents: 114
diff changeset
    48
0d36aade845e some stuff, don't remember what
nireco
parents: 114
diff changeset
    49
void Shot::onCollision() {
0d36aade845e some stuff, don't remember what
nireco
parents: 114
diff changeset
    50
//    world.removeGround(position, 20);
0d36aade845e some stuff, don't remember what
nireco
parents: 114
diff changeset
    51
}