src/proto2/GameState.cc
changeset 96 4a801210096c
parent 94 08bebac3d0c2
child 108 1b93045a5b0a
equal deleted inserted replaced
95:10704e1df844 96:4a801210096c
     1 
     1 
     2 #include "GameState.hh"
     2 #include "GameState.hh"
     3 #include "Engine.hh"
     3 #include "Engine.hh"
     4 
     4 
     5 void LocalPlayer::handleMove (PlayerInput_Move input) {
     5 void Player::handleMove (PlayerInput_Move input) {
     6     float fx = 0, fy = 0;
     6     float fx = 0;
     7 
     7 
     8     // handle up/down/left/right
     8     // handle left/right
     9     if (input & INPUT_MOVE_UP)
       
    10             fy -= PLAYER_MOVE_FORCE;
       
    11     
       
    12     if (input & INPUT_MOVE_DOWN)
       
    13             fy += PLAYER_MOVE_FORCE;
       
    14 
       
    15     if (input & INPUT_MOVE_LEFT)
     9     if (input & INPUT_MOVE_LEFT)
    16             fx -= PLAYER_MOVE_FORCE;
    10             fx -= PLAYER_MOVE_FORCE;
    17 
    11 
    18     if (input & INPUT_MOVE_RIGHT)
    12     if (input & INPUT_MOVE_RIGHT)
    19             fx += PLAYER_MOVE_FORCE;
    13             fx += PLAYER_MOVE_FORCE;
       
    14     
       
    15     // we behave differently depending on if we're in the air or on the ground
       
    16     if (inAir) {
       
    17         // apply horizontal force
       
    18         if (fx)
       
    19             applyForce(Vector(fx, 0), INPUT_INTERVAL_MS);
    20 
    20 
    21 	// If the player if on the ground make it crawl, jump or dig 
    21     } else {
    22 	if(!inAir) {
    22         // walk right
    23      	if(fy == 0)
    23         if (fx)
    24 			this->position = moveVertically(fx > 0);
    24             this->position = walk(fx > 0);
    25 		else
    25         
    26 			jump();
    26         // jump?
    27 	} else {
    27         if (input & INPUT_MOVE_JUMP)
    28 
    28             jump();    
    29     	if(fx) {
    29     }
    30         	// apply force
       
    31         	applyForce(Vector(fx, 0), INPUT_INTERVAL_MS);
       
    32     	}
       
    33 	}
       
    34 }
    30 }
    35 
    31 
    36 void Player::debugInfo (void) {
    32 void Player::debugInfo (void) {
    37 	Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir;
    33 	Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir;
    38 }
    34 }