diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-08-29 05:34:18 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-08-29 05:34:18 +0000 |
| commit | 0511e1152a13ad99b51a819a75ef457404e86d4c (patch) | |
| tree | d8e31b98f18f7e027ee72a9792248072d93e5852 /src/game/client/components/sounds.cpp | |
| parent | b22dd1488cdae53d27215fda051fea9bfc72ac1d (diff) | |
| download | zcatch-0511e1152a13ad99b51a819a75ef457404e86d4c.tar.gz zcatch-0511e1152a13ad99b51a819a75ef457404e86d4c.zip | |
added sound component
Diffstat (limited to 'src/game/client/components/sounds.cpp')
| -rw-r--r-- | src/game/client/components/sounds.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp new file mode 100644 index 00000000..569bbf01 --- /dev/null +++ b/src/game/client/components/sounds.cpp @@ -0,0 +1,42 @@ +#include <engine/e_client_interface.h> +#include <game/generated/gc_data.hpp> +#include <game/client/gameclient.hpp> +#include <game/client/components/camera.hpp> +#include "sounds.hpp" + +void SOUNDS::on_init() +{ + // setup sound channels + snd_set_channel(SOUNDS::CHN_GUI, 1.0f, 0.0f); + snd_set_channel(SOUNDS::CHN_MUSIC, 1.0f, 0.0f); + snd_set_channel(SOUNDS::CHN_WORLD, 0.9f, 1.0f); + snd_set_channel(SOUNDS::CHN_GLOBAL, 1.0f, 0.0f); +} + +void SOUNDS::on_render() +{ + // set listner pos + snd_set_listener_pos(gameclient.camera->center.x, gameclient.camera->center.y); +} + +void SOUNDS::play(int chn, int setid, float vol, vec2 pos) +{ + SOUNDSET *set = &data->sounds[setid]; + + if(!set->num_sounds) + return; + + if(set->num_sounds == 1) + { + snd_play_at(chn, set->sounds[0].id, 0, pos.x, pos.y); + return; + } + + // play a random one + int id; + do { + id = rand() % set->num_sounds; + } while(id == set->last); + snd_play_at(chn, set->sounds[id].id, 0, pos.x, pos.y); + set->last = id; +} |