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 Flame::Flame(const lisp::Lisp& reader)
26 : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2), source(0)
28 reader.get("radius", radius);
29 reader.get("speed", speed);
30 bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
31 start_position.y + sin(angle) * radius));
35 Flame::Flame(const Flame& other)
36 : BadGuy(other), angle(other.angle), radius(other.radius), speed(other.speed)
38 if (sound_manager->is_sound_enabled()) {
39 source.reset(sound_manager->create_sound_source("sounds/flame.wav"));
44 Flame::write(lisp::Writer& writer)
46 writer.start_list("flame");
48 writer.write_float("x", start_position.x);
49 writer.write_float("y", start_position.y);
50 writer.write_float("radius", radius);
51 writer.write_float("speed", speed);
53 writer.end_list("flame");
57 Flame::active_update(float elapsed_time)
59 angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
60 Vector newpos(start_position.x + cos(angle) * radius,
61 start_position.y + sin(angle) * radius);
62 movement = newpos - get_pos();
64 if (sound_manager->is_sound_enabled())
65 source->set_position(get_pos());
71 set_group(COLGROUP_TOUCHABLE);
73 if (!sound_manager->is_sound_enabled())
76 source.reset(sound_manager->create_sound_source("sounds/flame.wav"));
77 if(source.get() == NULL) {
78 log_warning << "Couldn't start flame sound" << std::endl;
81 source->set_position(get_pos());
82 source->set_looping(true);
83 source->set_gain(2.0);
84 source->set_reference_distance(32);
99 IMPLEMENT_FACTORY(Flame, "flame")