src/proto2/GameState.cc
author nireco
Fri, 28 Nov 2008 13:17:43 +0000
changeset 117 2877eef6c1d5
parent 116 0d36aade845e
child 122 16a73ebca810
permissions -rw-r--r--
digging

#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), INPUT_INTERVAL_MS);

    // 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);
}