Beispiel #1
0
/**
 * \brief Starts the "brandish" animation of the hero's sprites.
 */
void HeroSprites::set_animation_brandish() {

  set_tunic_animation("brandish");
  tunic_sprite->set_current_direction(1);
  stop_displaying_sword();
  stop_displaying_shield();
  stop_displaying_trail();
}
Beispiel #2
0
/**
 * \brief Starts the "walking_diagonal" animation of the hero's sprites.
 * \param direction8 the diagonal direction to take (1, 3, 5 or 7)
 */
void HeroSprites::set_animation_walking_diagonal(int direction8) {

  stop_displaying_sword();
  stop_displaying_shield();
  stop_displaying_trail();
  set_tunic_animation("walking_diagonal");
  tunic_sprite->set_current_direction(direction8 / 2);
}
Beispiel #3
0
/**
 * \brief Starts (or restarts) the "super_spin_attck" animation of the hero's sprites.
 */
void HeroSprites::set_animation_super_spin_attack() {

  set_tunic_animation("super_spin_attack");
  sword_sprite->set_current_animation("super_spin_attack");
  stop_displaying_sword_stars();
  stop_displaying_shield();
  stop_displaying_trail();
}
Beispiel #4
0
/**
 * \brief Starts the normal "walking" animation of the hero's sprites.
 */
void HeroSprites::set_animation_walking_normal() {

  set_animation_walking_common();

  if (equipment.has_ability(ABILITY_SHIELD)) {

    set_tunic_animation("walking_with_shield");

    shield_sprite->set_current_animation("walking");
    shield_sprite->set_current_direction(get_animation_direction());
  }
  else {
    set_tunic_animation("walking");
  }
  stop_displaying_sword();
  stop_displaying_trail();
}
Beispiel #5
0
/**
 * \brief Starts the "stopped" animation with sprites that represent
 * the hero swimming.
 */
void HeroSprites::set_animation_stopped_swimming() {

  set_animation_stopped_common();
  set_tunic_animation("swimming_stopped");
  stop_displaying_sword();
  stop_displaying_shield();
  stop_displaying_trail();
}
Beispiel #6
0
/**
 * \brief Starts the "falling" animation of the hero's sprites.
 */
void HeroSprites::set_animation_falling() {

  // show the animation
  set_tunic_animation("falling");
  stop_displaying_sword();
  stop_displaying_shield();
  stop_displaying_trail();
}
/**
 * \brief Starts the "swimming_fast" animation of the sprites.
 */
void HeroSprites::set_animation_swimming_fast() {

  set_animation_walking_common();

  set_tunic_animation("swimming_fast");
  stop_displaying_sword();
  stop_displaying_shield();
  stop_displaying_trail();
}
/**
 * \brief Starts the "stopped" animation with sprites that represent
 * the hero carrying something.
 *
 * If the hero actually carries an item, the carried item also takes a "stopped" animation.
 */
void HeroSprites::set_animation_stopped_carrying() {

  set_animation_stopped_common();
  set_tunic_animation("carrying_stopped");

  if (lifted_item != nullptr) {
    lifted_item->set_animation_stopped();
  }
  stop_displaying_trail();
}
/**
 * \brief Starts the "jumping" animation of the hero's sprites.
 */
void HeroSprites::set_animation_jumping() {

  set_tunic_animation("jumping");

  if (equipment.has_ability(Ability::SHIELD)) {
    shield_sprite->set_current_animation("stopped");
    shield_sprite->set_current_direction(get_animation_direction());
  }
  stop_displaying_sword();
  stop_displaying_trail();
}
/**
 * \brief Starts the "victory" animation of the hero's sprites.
 */
void HeroSprites::set_animation_victory() {

  set_tunic_animation("victory");
  tunic_sprite->set_current_direction(1);
  if (sword_sprite != nullptr) {
    sword_sprite->set_current_animation("victory");
    sword_sprite->set_current_direction(1);
  }
  stop_displaying_sword_stars();
  stop_displaying_shield();
  stop_displaying_trail();
}
/**
 * \brief Starts the "boomerang" animation of the hero's sprites.
 * \param tunic_preparing_animation Animation name of the hero's tunic sprite
 * when preparing the boomerang.
 */
void HeroSprites::set_animation_boomerang(
    const std::string& tunic_preparing_animation) {

  set_tunic_animation(tunic_preparing_animation);

  if (shield_sprite != nullptr
      && shield_sprite->has_animation("boomerang")) {
    shield_sprite->set_current_animation("boomerang");
  }
  else {
    stop_displaying_shield();
  }
  stop_displaying_sword();
  stop_displaying_trail();
}
/**
 * \brief Starts a custom animation of the hero's sprites.
 *
 * All sprites of the hero that have an animation with this name take the
 * animation. The ones that don't have such an animation are not displayed.
 * Many simple animations can be started with this function.
 * More complex one have dedicated functions.
 *
 * \param animation Name of the animation to give to the hero's sprites.
 * \param callback_ref Lua ref of a function to call when the animation ends
 * or an empty ref.
 */
void HeroSprites::set_animation(
    const std::string& animation,
    const ScopedLuaRef& callback_ref
) {

  if (tunic_sprite->has_animation(animation)) {
    set_tunic_animation(animation, callback_ref);
  }
  else {
    Debug::error("Sprite '" + tunic_sprite->get_animation_set_id() + "': Animation '" + animation + "' not found.");
  }

  if (shield_sprite != nullptr
      && shield_sprite->has_animation(animation)) {
    shield_sprite->set_current_animation(animation);
  }
  else {
    stop_displaying_shield();
  }

  if (sword_sprite != nullptr
      && sword_sprite->has_animation(animation)) {
    sword_sprite->set_current_animation(animation);
  }
  else {
    stop_displaying_sword();
  }

  if (sword_stars_sprite != nullptr
      && sword_stars_sprite->has_animation(animation)) {
    sword_stars_sprite->set_current_animation(animation);
  }
  else {
    stop_displaying_sword_stars();
  }

  if (trail_sprite != nullptr
      && trail_sprite->has_animation(animation)) {
    trail_sprite->set_current_animation(animation);
  }
  else {
    stop_displaying_trail();
  }
}
/**
 * \brief Starts the "stopped" animation of the hero's sprites with the sword loading.
 */
void HeroSprites::set_animation_stopped_sword_loading() {

  set_animation_stopped_common();

  int direction = get_animation_direction();

  set_tunic_animation("sword_loading_stopped");
  sword_sprite->set_current_animation("sword_loading_stopped");
  sword_sprite->set_current_direction(direction);
  sword_stars_sprite->set_current_animation("loading");
  sword_stars_sprite->set_current_direction(direction);

  if (equipment.has_ability(Ability::SHIELD)) {

    shield_sprite->set_current_animation("sword_loading_stopped");
    shield_sprite->set_current_direction(direction);
  }
  stop_displaying_trail();
}
/**
 * \brief Starts (or restarts) the "sword tapping" animation of the hero's sprites.
 */
void HeroSprites::set_animation_sword_tapping() {

  int direction = get_animation_direction();

  set_tunic_animation("sword_tapping");
  tunic_sprite->restart_animation();

  sword_sprite->set_current_animation("sword_tapping");
  sword_sprite->set_current_direction(direction);
  sword_sprite->restart_animation();
  sword_stars_sprite->stop_animation();

  if (equipment.has_ability(Ability::SHIELD)) {

    shield_sprite->set_current_animation("sword_tapping");
    shield_sprite->set_current_direction(direction);
    shield_sprite->restart_animation();
  }
  stop_displaying_trail();
}
Beispiel #15
0
/**
 * \brief Sets the animation set id to use for the tunic sprite.
 * \param sprite_id The tunic sprite animation set id.
 */
void HeroSprites::set_tunic_sprite_id(const std::string& sprite_id) {

  if (sprite_id == this->tunic_sprite_id) {
    return;
  }

  this->tunic_sprite_id = sprite_id;

  std::string animation;
  int direction = -1;
  if (tunic_sprite != nullptr) {
    // Delete the previous sprite, but save its animation and direction.
    animation = tunic_sprite->get_current_animation();
    direction = tunic_sprite->get_current_direction();
    hero.remove_sprite(*tunic_sprite);
    tunic_sprite = nullptr;
  }

  tunic_sprite = hero.create_sprite(sprite_id, "tunic");
  tunic_sprite->enable_pixel_collisions();
  if (!animation.empty()) {
    set_tunic_animation(animation);
    tunic_sprite->set_current_direction(direction);
  }

  has_default_tunic_sprite = (sprite_id == get_default_tunic_sprite_id());

  // Synchronize other sprites to the new tunic sprite.
  if (sword_sprite != nullptr) {
    sword_sprite->set_synchronized_to(tunic_sprite);
  }
  if (shield_sprite != nullptr) {
    shield_sprite->set_synchronized_to(tunic_sprite);
  }

  reorder_sprites();
  recompute_sprites_bounding_box();
}
/**
 * \brief Sets the animation set id to use for the tunic sprite.
 * \param sprite_id The tunic sprite animation set id.
 */
void HeroSprites::set_tunic_sprite_id(const std::string& sprite_id) {

  if (sprite_id == this->tunic_sprite_id) {
    return;
  }

  this->tunic_sprite_id = sprite_id;

  std::string animation;
  int direction = -1;
  if (tunic_sprite != nullptr) {
    // Delete the previous sprite, but save its animation and direction.
    animation = tunic_sprite->get_current_animation();
    direction = tunic_sprite->get_current_direction();
    tunic_sprite = nullptr;
  }

  tunic_sprite = std::make_shared<Sprite>(sprite_id);
  tunic_sprite->enable_pixel_collisions();
  if (!animation.empty()) {
    set_tunic_animation(animation);
    tunic_sprite->set_current_direction(direction);
  }

  if (sprite_id == get_default_tunic_sprite_id()) {
    has_default_tunic_sprite = true;
  }

  // Synchronize other sprites to the new tunic sprite.
  if (sword_sprite != nullptr) {
    sword_sprite->set_synchronized_to(tunic_sprite);
  }
  if (shield_sprite != nullptr) {
    shield_sprite->set_synchronized_to(tunic_sprite);
  }
}
/**
 * \brief Changes the animation of the tunic sprite.
 *
 * Cancels the Lua callback if any.
 *
 * \param animation The animation name of the tunic sprite.
 */
void HeroSprites::set_tunic_animation(const std::string& animation) {

  set_tunic_animation(animation, ScopedLuaRef());
}
/**
 * \brief Starts the "lifting" animation of the hero's sprites.
 */
void HeroSprites::set_animation_lifting() {

  set_tunic_animation("lifting");
  stop_displaying_shield();
  stop_displaying_trail();
}