src/proto2/GameState.cc
author nireco
Tue, 02 Dec 2008 00:23:16 +0000
changeset 174 073f25a84f60
parent 170 fe74105c07ea
child 180 bfe1077edab3
permissions -rw-r--r--
removed bad comment

#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) && (velocity.x > -PLAYER_MAX_SPEED))
        fx -= PLAYER_MOVE_FORCE;

    if ((input & INPUT_MOVE_RIGHT) && (velocity.x < PLAYER_MAX_SPEED))
        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) {
        if ((input & INPUT_MOVE_LEFT))
            jump(-1);
        else if ((input & INPUT_MOVE_RIGHT))
            jump(1);
        else
            jump(0);
    }

    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, 15);
    }
}

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

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