/** * \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(); } }
/** * @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(); } } } }
/** * \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(); } } }