コード例 #1
0
ファイル: HeroSprites.cpp プロジェクト: Maxs1789/solarus
/**
 * \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();
}
コード例 #2
0
ファイル: HeroSprites.cpp プロジェクト: MilkshakeCat/solarus
/**
 * \brief Sets the sound to play when using the sword.
 * \param sound_id The sword sound id.
 * An empty string means no sword sound.
 */
void HeroSprites::set_sword_sound_id(const std::string& sound_id) {

  if (sound_id == this->sword_sound_id) {
    return;
  }

  this->sword_sound_id = sound_id;

  has_default_sword_sound = (sound_id == get_default_sword_sound_id());
}