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
22 #include "ambient_sound.h"
23 #include "object_factory.h"
24 #include "lisp/lisp.h"
28 * Ambient Sound Source, beta version. Features:
30 * - "disc" like structure. Full volume up to some distance
31 * (distance_bias) to the source, then fading proportional to
32 * inverse square distance
34 * This is experimental, clicks sometimes and still leaks mem
39 AmbientSound::AmbientSound(const lisp::Lisp& lisp)
43 lisp.get("x", position.x);
44 lisp.get("y", position.y);
45 lisp.get("distance_factor",distance_factor);
46 lisp.get("distance_bias" ,distance_bias );
47 lisp.get("sample" ,sample );
49 if (distance_factor == 0)
50 silence_distance = 10e99;
52 silence_distance = distance_factor*10e2;
61 AmbientSound::hit(Player& )
66 AmbientSound::startPlaying()
68 playing=sound_manager->play_sound(sample,-1);
69 volume_ptr=new float[2];
72 sound_manager->register_effect(playing,&SoundManager::volume_adjust,
73 NULL,(void *)volume_ptr);
77 AmbientSound::action(float)
79 float dx=Sector::current()->player->get_pos().x-position.x;
80 float dy=Sector::current()->player->get_pos().y-position.y;
81 float distance=sqrt(dx*dx+dy*dy);
83 distance-=distance_bias;
88 volume_ptr[0]=1/(1+distance*distance_factor); // inverse square of distance
93 AmbientSound::draw(DrawingContext &dc)
96 sprite->draw(dc,position,1);
100 IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");