0de567db2ab98a986501963ac543e5d763dfac71
[supertux.git] / src / badguy / flame.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
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.
10 //
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.
15 //
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.
19
20 #include <config.h>
21
22 #include "flame.hpp"
23 #include "log.hpp"
24
25 static const std::string SOUNDFILE = "sounds/flame.wav";
26
27 Flame::Flame(const lisp::Lisp& reader)
28   : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2)
29 {
30   reader.get("radius", radius);
31   reader.get("speed", speed);
32   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
33                       start_position.y + sin(angle) * radius));
34   countMe = false;
35   sound_manager->preload(SOUNDFILE);
36
37   set_colgroup_active(COLGROUP_TOUCHABLE);
38 }
39
40 void
41 Flame::write(lisp::Writer& writer)
42 {
43   writer.start_list("flame");
44
45   writer.write("x", start_position.x);
46   writer.write("y", start_position.y);
47   writer.write("radius", radius);
48   writer.write("speed", speed);
49
50   writer.end_list("flame");
51 }
52
53 void
54 Flame::active_update(float elapsed_time)
55 {
56   angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
57   Vector newpos(start_position.x + cos(angle) * radius,
58                 start_position.y + sin(angle) * radius);
59   movement = newpos - get_pos();
60
61   sound_source->set_position(get_pos());
62 }
63
64 void
65 Flame::activate()
66 {
67   sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
68   sound_source->set_position(get_pos());
69   sound_source->set_looping(true);
70   sound_source->set_gain(2.0);
71   sound_source->set_reference_distance(32);
72   sound_source->play();
73 }
74
75 void
76 Flame::deactivate()
77 {
78   sound_source.reset();
79 }
80
81 void
82 Flame::kill_fall()
83 {
84 }
85
86 IMPLEMENT_FACTORY(Flame, "flame")