src/proto2/GameState.cc
author saiam
Sat, 29 Nov 2008 17:29:53 +0000
changeset 133 c05e84ccc4b3
parent 122 16a73ebca810
child 153 73402d5b778e
permissions -rw-r--r--
Made unnecessarily virtual function PhysicsObject::applyForce nonvirtual

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