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