Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / badguy / flame.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "badguy/flame.hpp"
18
19 #include "audio/sound_manager.hpp"
20 #include "lisp/lisp.hpp"
21 #include "supertux/object_factory.hpp"
22
23 #include <math.h>
24
25 static const std::string SOUNDFILE = "sounds/flame.wav";
26
27 Flame::Flame(const Reader& reader) :
28   BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), 
29   angle(0), 
30   radius(100), 
31   speed(2),
32   sound_source()
33 {
34   reader.get("radius", radius);
35   reader.get("speed", speed);
36   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
37                       start_position.y + sin(angle) * radius));
38   countMe = false;
39   sound_manager->preload(SOUNDFILE);
40
41   set_colgroup_active(COLGROUP_TOUCHABLE);
42 }
43
44 void
45 Flame::active_update(float elapsed_time)
46 {
47   angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
48   Vector newpos(start_position.x + cos(angle) * radius,
49                 start_position.y + sin(angle) * radius);
50   movement = newpos - get_pos();
51
52   sound_source->set_position(get_pos());
53 }
54
55 void
56 Flame::activate()
57 {
58   sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
59   sound_source->set_position(get_pos());
60   sound_source->set_looping(true);
61   sound_source->set_gain(2.0);
62   sound_source->set_reference_distance(32);
63   sound_source->play();
64 }
65
66 void
67 Flame::deactivate()
68 {
69   sound_source.reset();
70 }
71
72 void
73 Flame::kill_fall()
74 {
75 }
76
77 IMPLEMENT_FACTORY(Flame, "flame");
78
79 /* EOF */