Example #1
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();
    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);
  }

  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);
  }
}
Example #2
0
/**
 * \brief Loads (or reloads) the sprites and sounds of the hero and his
 * equipment.
 *
 * The sprites and sounds loaded may depend on his tunic, sword and shield as
 * specified in the savegame.
 * This function must be called at the game beginning
 * and as soon as the hero's equipment is changed.
 */
void HeroSprites::rebuild_equipment() {

  // Make the tunic sprite be the default one.
  hero.set_default_sprite_name("tunic");

  int animation_direction = -1;
  if (tunic_sprite != nullptr) {
    // Save the direction.
    animation_direction = tunic_sprite->get_current_direction();
  }

  // The hero's body.
  if (has_default_tunic_sprite) {
    set_tunic_sprite_id(get_default_tunic_sprite_id());
  }

  // The hero's shadow.
  if (shadow_sprite == nullptr) {
    shadow_sprite = hero.create_sprite("entities/shadow", "shadow");
    shadow_sprite->set_current_animation("big");
  }

  // The hero's sword.
  if (has_default_sword_sprite) {
    set_sword_sprite_id(get_default_sword_sprite_id());
  }

  if (has_default_sword_sound) {
    set_sword_sound_id(get_default_sword_sound_id());
  }

  const int sword_number = equipment.get_ability(Ability::SWORD);
  if (sword_number > 0) {
    // TODO make this sprite depend on the sword sprite: sword_sprite_id + "_stars"
    std::ostringstream oss;
    oss << "hero/sword_stars" << sword_number;
    sword_stars_sprite = hero.create_sprite(oss.str(), "sword_stars");
    sword_stars_sprite->stop_animation();
  }

  // The hero's shield.
  if (has_default_shield_sprite) {
    set_shield_sprite_id(get_default_shield_sprite_id());
  }

  // The trail.
  trail_sprite = hero.create_sprite("hero/trail", "trail");
  trail_sprite->stop_animation();

  // Restore the animation direction.
  if (animation_direction != -1) {
    set_animation_direction(animation_direction);
  }

  reorder_sprites();
}
Example #3
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();
}