X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fflame.cpp;h=8f035a7f436cc1dc192c87f4a88e2e8019c85c87;hb=13c84268f16872f9b442251c4175a3a1a7a7899a;hp=330d8280b77e44a51b78ba63621bd0001bc2c4bf;hpb=78e9b27b7059c9b9b16a7f871ab71f751ec75323;p=supertux.git diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index 330d8280b..8f035a7f4 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -22,22 +22,19 @@ #include "flame.hpp" #include "log.hpp" +static const std::string SOUNDFILE = "sounds/flame.wav"; + Flame::Flame(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2), source(0) + : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2) { reader.get("radius", radius); reader.get("speed", speed); bbox.set_pos(Vector(start_position.x + cos(angle) * radius, start_position.y + sin(angle) * radius)); countMe = false; -} + sound_manager->preload(SOUNDFILE); -Flame::Flame(const Flame& other) - : BadGuy(other), angle(other.angle), radius(other.radius), speed(other.speed) -{ - if (sound_manager->is_sound_enabled()) { - source.reset(sound_manager->create_sound_source("sounds/flame.wav")); - } + set_colgroup_active(COLGROUP_TOUCHABLE); } void @@ -56,39 +53,29 @@ Flame::write(lisp::Writer& writer) void Flame::active_update(float elapsed_time) { - angle = fmodf(angle + elapsed_time * speed, 2*M_PI); + angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI)); Vector newpos(start_position.x + cos(angle) * radius, start_position.y + sin(angle) * radius); movement = newpos - get_pos(); - if (sound_manager->is_sound_enabled()) - source->set_position(get_pos()); + sound_source->set_position(get_pos()); } void Flame::activate() { - set_group(COLGROUP_TOUCHABLE); - - if (!sound_manager->is_sound_enabled()) - return; - - source.reset(sound_manager->create_sound_source("sounds/flame.wav")); - if(source.get() == NULL) { - log_warning << "Couldn't start flame sound" << std::endl; - return; - } - source->set_position(get_pos()); - source->set_looping(true); - source->set_gain(2.0); - source->set_reference_distance(32); - source->play(); + sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); + sound_source->set_position(get_pos()); + sound_source->set_looping(true); + sound_source->set_gain(2.0); + sound_source->set_reference_distance(32); + sound_source->play(); } void Flame::deactivate() { - source.release(); + sound_source.reset(); } void @@ -97,4 +84,3 @@ Flame::kill_fall() } IMPLEMENT_FACTORY(Flame, "flame") -