4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "lisp/writer.hpp"
26 #include "lisp/lisp.hpp"
27 #include "object_factory.hpp"
28 #include "audio/sound_manager.hpp"
32 static const std::string SOUNDFILE = "sounds/flame.wav";
34 Flame::Flame(const lisp::Lisp& reader)
35 : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2)
37 reader.get("radius", radius);
38 reader.get("speed", speed);
39 bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
40 start_position.y + sin(angle) * radius));
42 sound_manager->preload(SOUNDFILE);
44 set_colgroup_active(COLGROUP_TOUCHABLE);
48 Flame::write(lisp::Writer& writer)
50 writer.start_list("flame");
52 writer.write("x", start_position.x);
53 writer.write("y", start_position.y);
54 writer.write("radius", radius);
55 writer.write("speed", speed);
57 writer.end_list("flame");
61 Flame::active_update(float elapsed_time)
63 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
64 Vector newpos(start_position.x + cos(angle) * radius,
65 start_position.y + sin(angle) * radius);
66 movement = newpos - get_pos();
68 sound_source->set_position(get_pos());
74 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
75 sound_source->set_position(get_pos());
76 sound_source->set_looping(true);
77 sound_source->set_gain(2.0);
78 sound_source->set_reference_distance(32);
93 IMPLEMENT_FACTORY(Flame, "flame")