示例#1
0
void
Player::handle_input()
{
  if (ghost_mode) {
    handle_input_ghost();
    return;
  }

  if(!controller->hold(Controller::ACTION) && grabbed_object) {
    // move the grabbed object a bit away from tux
    Vector pos = get_pos() + 
        Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
                bbox.get_height()*0.66666 - 32);
    Rect dest(pos, pos + Vector(32, 32));
    if(Sector::current()->is_free_space(dest)) {
      MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
      if(moving_object) {
        moving_object->set_pos(pos);
      } else {
        log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
      }
      grabbed_object->ungrab(*this, dir);
      grabbed_object = NULL;
    }
  }
 
  /* Handle horizontal movement: */
  if (!backflipping) handle_horizontal_input();
  
  /* Jump/jumping? */
  if (on_ground() && !controller->hold(Controller::JUMP))
    can_jump = true;

  /* Handle vertical movement: */
  handle_vertical_input();

  /* Shoot! */
  if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
    if(Sector::current()->add_bullet(
         get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) 
                      : Vector(32, bbox.get_height()/2)),
         physic.get_velocity_x(), dir))
      shooting_timer.start(SHOOTING_TIME);
  }
  
  /* Duck or Standup! */
  if (controller->hold(Controller::DOWN)) do_duck(); else do_standup();

}
示例#2
0
void
Player::handle_input()
{
  if (ghost_mode) {
    handle_input_ghost();
    return;
  }
  if (climbing) {
    handle_input_climbing();
    return;
  }

  /* Peeking */
  if( controller->released( Controller::PEEK_LEFT ) || controller->released( Controller::PEEK_RIGHT ) ) {
    peekingX = AUTO;
  }
  if( controller->released( Controller::PEEK_UP ) || controller->released( Controller::PEEK_DOWN ) ) {
    peekingY = AUTO;
  }
  if( controller->pressed( Controller::PEEK_LEFT ) ) {
    peekingX = LEFT;
  }
  if( controller->pressed( Controller::PEEK_RIGHT ) ) {
    peekingX = RIGHT;
  }
  if(!backflipping && !jumping && on_ground()) {
    if( controller->pressed( Controller::PEEK_UP ) ) {
      peekingY = UP;
    } else if( controller->pressed( Controller::PEEK_DOWN ) ) {
      peekingY = DOWN;
    }
  }

  /* Handle horizontal movement: */
  if (!backflipping) handle_horizontal_input();

  /* Jump/jumping? */
  if (on_ground())
    can_jump = true;

  /* Handle vertical movement: */
  handle_vertical_input();

  handle_jump_helper();

  /* Shoot! */
  if (controller->pressed(Controller::ACTION) && (player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS)) {
    if(Sector::current()->add_bullet(
         get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
                      : Vector(32, bbox.get_height()/2)),
         player_status,
         physic.get_velocity_x(), dir))
      shooting_timer.start(SHOOTING_TIME);
  }

  /* Duck or Standup! */
  if (controller->hold(Controller::DOWN)) {
    do_duck();
  } else {
    do_standup();
  }

  /* grabbing */
  try_grab();

  if(!controller->hold(Controller::ACTION) && grabbed_object) {
    MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
    if(moving_object) {
      // move the grabbed object a bit away from tux
      Rectf grabbed_bbox = moving_object->get_bbox();
      Rectf dest_;
      dest_.p2.y = bbox.get_top() + bbox.get_height()*0.66666;
      dest_.p1.y = dest_.p2.y - grabbed_bbox.get_height();
      if(dir == LEFT) {
        dest_.p2.x = bbox.get_left() - 1;
        dest_.p1.x = dest_.p2.x - grabbed_bbox.get_width();
      } else {
        dest_.p1.x = bbox.get_right() + 1;
        dest_.p2.x = dest_.p1.x + grabbed_bbox.get_width();
      }
      if(Sector::current()->is_free_of_tiles(dest_, true)) {
        moving_object->set_pos(dest_.p1);
        if(controller->hold(Controller::UP)) {
          grabbed_object->ungrab(*this, UP);
        } else {
          grabbed_object->ungrab(*this, dir);
        }
        grabbed_object = NULL;
      }
    } else {
      log_debug << "Non MovingObject grabbed?!?" << std::endl;
    }
  }

  /* stop backflipping at will */
  if( backflipping && ( !controller->hold(Controller::JUMP) && !backflip_timer.started()) ){
    backflipping = false;
    backflip_direction = 0;
    sprite->set_angle(0.0f);
  }
}