X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fflame.cpp;h=8f035a7f436cc1dc192c87f4a88e2e8019c85c87;hb=13c84268f16872f9b442251c4175a3a1a7a7899a;hp=83845a6dd92f6fa816c7394c92bc18621ebbf1ce;hpb=d46c78c842ab4090a3f46e560c891234167f124b;p=supertux.git diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index 83845a6dd..8f035a7f4 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -1,22 +1,44 @@ +// $Id$ +// +// SuperTux +// 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 +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// 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. + #include -#include "flame.h" +#include "flame.hpp" +#include "log.hpp" + +static const std::string SOUNDFILE = "sounds/flame.wav"; -Flame::Flame(LispReader& reader) - : angle(0), radius(100), speed(2) +Flame::Flame(const lisp::Lisp& reader) + : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2) { - reader.read_float("x", start_position.x); - reader.read_float("y", start_position.y); - reader.read_float("radius", radius); - reader.read_float("speed", speed); + 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("flame"); + countMe = false; + sound_manager->preload(SOUNDFILE); + + set_colgroup_active(COLGROUP_TOUCHABLE); } void -Flame::write(LispWriter& writer) +Flame::write(lisp::Writer& writer) { writer.start_list("flame"); @@ -29,12 +51,31 @@ Flame::write(LispWriter& writer) } void -Flame::active_action(float elapsed_time) +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(); + + sound_source->set_position(get_pos()); +} + +void +Flame::activate() +{ + 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() +{ + sound_source.reset(); } void @@ -42,3 +83,4 @@ Flame::kill_fall() { } +IMPLEMENT_FACTORY(Flame, "flame")