1 // ambient_sound.cpp basti_
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.
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.
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
23 #include "ambient_sound.h"
24 #include "object_factory.h"
25 #include "lisp/lisp.h"
29 * Ambient Sound Source, beta version. Features:
31 * - "disc" like structure. Full volume up to some distance
32 * (distance_bias) to the source, then fading proportional to
33 * inverse square distance
35 * This is experimental, clicks sometimes and still leaks mem
40 AmbientSound::AmbientSound(const lisp::Lisp& lisp)
44 lisp.get("x", position.x);
45 lisp.get("y", position.y);
46 lisp.get("distance_factor",distance_factor);
47 lisp.get("distance_bias" ,distance_bias );
48 lisp.get("sample" ,sample );
50 if (distance_factor == 0)
51 silence_distance = 10e99;
53 silence_distance = distance_factor*10e2;
62 AmbientSound::hit(Player& )
67 AmbientSound::startPlaying()
69 playing=sound_manager->play_sound(sample,-1);
70 volume_ptr=new float[2];
73 sound_manager->register_effect(playing,&SoundManager::volume_adjust,
74 NULL,(void *)volume_ptr);
78 AmbientSound::action(float)
80 float dx=Sector::current()->player->get_pos().x-position.x;
81 float dy=Sector::current()->player->get_pos().y-position.y;
82 float distance=sqrt(dx*dx+dy*dy);
84 distance-=distance_bias;
89 volume_ptr[0]=1/(1+distance*distance_factor); // inverse square of distance
94 AmbientSound::draw(DrawingContext &dc)
97 sprite->draw(dc,position,1);
101 IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");