Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / object / ambient_sound.hpp
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 /**
18  *  Ambient Sound Source, gamma version. Features:
19  *
20  *  - "rounded rectangle" geometry with position, dimension and
21  *    "rounding radius" (extending in all directions) of a 100%
22  *    volume area, adjustable maximum volume, inverse square
23  *    falloff outside area.
24  *
25  *  - degenerates gracefully to a disc for dimension=0
26  *
27  *  - parameters:
28  *
29  *    x, y               position
30  *    width, height      dimension
31  *    distance_factor    high = steep falloff
32  *    distance_bias      high = big "100% disc"
33  *    silence_distance   defaults reasonably.
34  *    sample             sample to be played back in loop mode
35  *
36  *      basti_
37  */
38
39 #ifndef HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
40 #define HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
41
42 #include "scripting/ambient_sound.hpp"
43 #include "supertux/game_object.hpp"
44 #include "supertux/script_interface.hpp"
45 #include "util/reader_fwd.hpp"
46
47 class Player;
48 class SoundSource;
49
50 class AmbientSound : public GameObject, 
51                      public ScriptInterface, 
52                      public Scripting::AmbientSound
53 {
54 public:
55   AmbientSound(const Reader& lisp);
56   AmbientSound(Vector pos, float factor, float bias, float vol, std::string file);
57   ~AmbientSound();
58
59   void set_pos(Vector newpos)
60   {
61     position=newpos;
62   }
63   const Vector get_pos() const
64   {
65     return position;
66   }
67
68   /**
69    * @name Scriptable Methods
70    * @{
71    */
72   void set_pos(float x, float y);
73   float get_pos_x() const;
74   float get_pos_y() const;
75   /**
76    * @}
77    */
78
79 protected:
80   virtual void hit(Player& player);
81   virtual void update(float time);
82   virtual void draw(DrawingContext&);
83   virtual void start_playing();
84   virtual void stop_playing();
85   virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
86   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
87 private:
88   std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
89   Vector position;
90   Vector dimension;
91
92   std::string sample;
93   SoundSource* sound_source;
94   int latency;
95
96   float distance_factor;  /// distance scaling
97   float distance_bias;    /// 100% volume disc radius
98   float silence_distance; /// not implemented yet
99
100   float maximumvolume; /// maximum volume
101   float targetvolume;  /// how loud we want to be
102   float currentvolume; /// how loud we are
103
104   float * volume_ptr; /// this will be used by the volume adjustment effect.
105 };
106
107 #endif
108
109 /* EOF */