/** * @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 Notifies this state that the walking speed has changed. * * If the hero can walk in this state, the state should modify its movement * to set the new speed. */ void Hero::PlayerMovementState::notify_walking_speed_changed() { if (get_player_movement() != NULL) { get_player_movement()->set_moving_speed(hero.get_walking_speed()); } }
/** * \brief Returns the direction of the hero's movement as defined by the controls applied by the player * and the movements allowed is the current state. * * If he is not moving, -1 is returned. * This direction may be different from the real movement direction because of obstacles. * * \return the hero's wanted direction between 0 and 7, or -1 if he is stopped */ int Hero::PlayerMovementState::get_wanted_movement_direction8() { return get_player_movement()->get_wanted_direction8(); }