converted sounds back to .wav
[supertux.git] / src / badguy / flame.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 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
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include "flame.hpp"
24
25 Flame::Flame(const lisp::Lisp& reader)
26   : angle(0), radius(100), speed(2), source(0)
27 {
28   reader.get("x", start_position.x);
29   reader.get("y", start_position.y);
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   bbox.set_size(32, 32);  
35   sprite = sprite_manager->create("flame");
36   countMe = false;
37 }
38
39 Flame::~Flame()
40 {
41   delete source;
42 }
43
44 void
45 Flame::write(lisp::Writer& writer)
46 {
47   writer.start_list("flame");
48
49   writer.write_float("x", start_position.x);
50   writer.write_float("y", start_position.y);
51   writer.write_float("radius", radius);
52   writer.write_float("speed", speed);
53
54   writer.end_list("flame");
55 }
56
57 void
58 Flame::active_update(float elapsed_time)
59 {
60   angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
61   Vector newpos(start_position.x + cos(angle) * radius,
62                 start_position.y + sin(angle) * radius);
63   movement = newpos - get_pos();
64
65   source->set_position(get_pos());
66 }
67
68 void
69 Flame::activate()
70 {
71   delete source;
72   source = sound_manager->create_sound_source("sounds/flame.wav");
73   if(!source) {
74     std::cerr << "Couldn't start flame sound.\n";
75     return;
76   }
77   source->set_position(get_pos());
78   source->set_looping(true);
79   source->set_gain(2.0);
80   source->set_reference_distance(32);
81   source->play();
82 }
83
84 void
85 Flame::deactivate()
86 {
87   delete source;
88   source = 0;
89 }
90
91 void
92 Flame::kill_fall()
93 {
94 }
95
96 IMPLEMENT_FACTORY(Flame, "flame")
97