03d33b5ceca9769c5925dd1a3dde056db539dcc1
[supertux.git] / src / object / ambient_sound.hpp
1 // ambient_sound.h   basti_
2 // 
3 //  SuperTux
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 2
8 //  of the License, or (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 // 
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 //  02111-1307, USA.
19
20 /**
21  *  Ambient Sound Source, gamma version. Features:
22  *
23  *  - "rounded rectancle" geometry with position, dimension and 
24  *    "rounding radius" (extending in all directions) of a 100% 
25  *    volume area, adjustable maximum volume, inverse square 
26  *    falloff outside area.
27  *  
28  *  - degenerates gracefully to a disc for dimension=0
29  *  
30  *  - parameters:
31  *
32  *    x, y               position
33  *    width, height      dimension
34  *    distance_factor    high = steep fallofff
35  *    distance_bias      high = big "100% disc"
36  *    silence_distance   defaults reasonably.
37  *    sample             sample to be played back in loop mode
38  * 
39  *      basti_ 
40  */
41
42 #ifndef __AMBIENT_SOUND_H__
43 #define __AMBIENT_SOUND_H__
44
45 #include "game_object.hpp"
46 #include "resources.hpp"
47 #include "player.hpp"
48
49 class SoundSource;
50
51 class AmbientSound : public GameObject
52 {
53 public:
54   AmbientSound(const lisp::Lisp& lisp);
55   AmbientSound(Vector pos, float factor, float bias, float vol, std::string file);
56   ~AmbientSound();
57 protected:
58   virtual void hit(Player& player);
59   virtual void update(float time);
60   virtual void draw(DrawingContext&);
61   virtual void start_playing();
62   virtual void stop_playing();
63 private:
64   Vector position;
65   Vector dimension;
66
67   std::string sample;
68   SoundSource* sound_source;
69   int latency;
70
71   float distance_factor;  /// distance scaling
72   float distance_bias;    /// 100% volume disc radius
73   float silence_distance; /// not implemented yet 
74
75   float maximumvolume; /// maximum volume
76   float targetvolume;  /// how loud we want to be
77   float currentvolume; /// how loud we are
78
79   float * volume_ptr; /// this will be used by the volume adjustment effect.
80 };
81
82 #endif
83