X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fflame.cpp;h=7f8d3562e4e4686bce2a5fd37645de39ae6ac369;hb=431cd7ea828d16f2d6a5b42fd2bc8560c5f5a468;hp=b3f3fa355c6119e08967bcd54800fcaa5103431c;hpb=e6a940db5904743e8220491ce10b5107e119a44c;p=supertux.git diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index b3f3fa355..7f8d3562e 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,33 +12,27 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include "flame.hpp" #include "log.hpp" +static const std::string SOUNDFILE = "sounds/flame.wav"; + Flame::Flame(const lisp::Lisp& reader) - : 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("x", start_position.x); - reader.get("y", start_position.y); reader.get("radius", radius); reader.get("speed", speed); bbox.set_pos(Vector(start_position.x + cos(angle) * radius, start_position.y + sin(angle) * radius)); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/creatures/flame/flame.sprite"); countMe = false; -} - -Flame::~Flame() -{ - delete source; + sound_manager->preload(SOUNDFILE); } void @@ -57,39 +51,31 @@ 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() { - if (!sound_manager->is_sound_enabled()) - return; + set_group(COLGROUP_TOUCHABLE); - delete source; - source = sound_manager->create_sound_source("sounds/flame.wav"); - if(!source) { - 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() { - delete source; - source = 0; + sound_source.reset(); } void @@ -98,4 +84,3 @@ Flame::kill_fall() } IMPLEMENT_FACTORY(Flame, "flame") -