Пример #1
0
/**
 * @brief Updates this state.
 */
void Hero::FreeState::update() {

  PlayerMovementState::update();

  if (!suspended
      && pushing_direction4 != -1					// the hero is trying to push
      && get_wanted_movement_direction8() != pushing_direction4 * 2) {	// but his movement direction has changed

    pushing_direction4 = -1; // stop trying to push
  }
}
Пример #2
0
/**
 * \brief Notifies this state that the hero has just failed to change its
 * position because of obstacles.
 */
void Hero::SwordLoadingState::notify_obstacle_reached() {

  PlayerMovementState::notify_obstacle_reached();

  Detector* facing_entity = hero.get_facing_entity();

  if (hero.is_facing_point_on_obstacle()     // he is really facing an obstacle
      && get_wanted_movement_direction8() == get_sprites().get_animation_direction8()   // he is trying to move towards the obstacle
      && (facing_entity == NULL || !facing_entity->is_sword_ignored())) {               // the obstacle allows him to tap with his sword

    hero.set_state(new SwordTappingState(hero));
  }
}
Пример #3
0
/**
 * \brief Notifies this state that the movement has changed.
 *
 * This function is called when the hero's movement direction changes (for instance
 * because the player pressed or released a directional key, or the hero just reached an obstacle).
 * The animations and collisions should be updated according to the new movement.
 */
void Hero::PlayerMovementState::notify_movement_changed() {

  // the movement has changed: update the animation of the sprites

  bool movement_walking = get_wanted_movement_direction8() != -1;
  bool sprites_walking = get_sprites().is_walking();

  if (movement_walking && !sprites_walking) {
    set_animation_walking();
  }
  else if (!movement_walking && sprites_walking) {
    set_animation_stopped();
  }
}
Пример #4
0
/**
 * @brief Starts this state.
 *
 * This function is called automatically when this state becomes the active state of the hero.
 *
 * @param previous_state the previous state
 */
void Hero::PlayerMovementState::start(State *previous_state) {

  hero.set_movement(new PlayerMovement(hero.get_walking_speed()));

  if (is_current_state()) { // yes, the state may have already changed
    get_player_movement()->compute_movement();
    if (is_current_state()) {
      if (get_wanted_movement_direction8() != -1) {
        set_animation_walking();
      }
      else {
        set_animation_stopped();
      }
    }
  }
}
Пример #5
0
/**
 * \brief Updates this state.
 */
void Hero::SwimmingState::update() {

  PlayerMovementState::update();

  if (is_suspended() || !is_current_state()) {
    return;
  }

  Hero& hero = get_hero();
  if (hero.get_ground_below() != GROUND_DEEP_WATER) {
    hero.set_state(new FreeState(hero));
  }
  else if (fast_swimming && System::now() >= end_fast_swim_date) {
    fast_swimming = false;
    hero.set_walking_speed(get_slow_swimming_speed());

    if (get_wanted_movement_direction8() != -1) {
      set_animation_walking();
    }
    else {
      set_animation_stopped();
    }
  }
}