src/proto2/GameState.cc
author saiam
Mon, 24 Nov 2008 23:04:22 +0000
changeset 108 1b93045a5b0a
parent 96 4a801210096c
child 114 71f7e9d3d052
permissions -rw-r--r--
T?ht?in lis?tty, tosin se piirret??n tosi rumasti.

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

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

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

        // we behave differently depending on if we're in the air or on the ground
        if (inAir) {
            // apply horizontal force
            if (fx)
                applyForce(Vector(fx, 0), INPUT_INTERVAL_MS);

        } else {
            // walk right
            if (fx)
                this->position = walk(fx > 0);
        
            // jump?
            if (input & INPUT_MOVE_JUMP)
                jump();    
        }
}

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