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)

#include "GameState.hh"
#include "Engine.hh"

void Player::handleMove (PlayerInput_Move input) {
    float fx = 0; // Force in x-direction
    float da = 0; // Crosshair angle

    // handle left/right
    if (input & INPUT_MOVE_LEFT)
        fx -= PLAYER_MOVE_FORCE;

    if (input & INPUT_MOVE_RIGHT)
        fx += PLAYER_MOVE_FORCE;

    if (input & INPUT_MOVE_UP)
        da += CROSSHAIR_ANGLE_SPEED;

    if (input & INPUT_MOVE_DOWN)
        da -= CROSSHAIR_ANGLE_SPEED;

    if (input & INPUT_MOVE_JUMP)
        jump();

    this->changeAim(da); // Move crosshair

    // Player facing
    if (fx < 0) setFacing(false);
    else if (fx > 0) setFacing(true);

    // Apply force
    applyForce(Vector(fx, 0));

    // dig/shoot or something
    if (input & INPUT_MOVE_DIG) {
        // Should create Shot which destroys ground, but also should be destroyed then,
        // but it doesn't.
        // But this now just segfaults
//        world.addObject(new Shot(state, position, true));

        world.removeGround(position, 10);
    }
}

void Player::debugInfo (void) {
    Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir;
}

void Shot::onCollision() {
//    world.removeGround(position, 20);
}