From 18c1dfbb78d98516f5480f8199910fe41ac904df Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 28 Oct 2023 10:52:18 +0200 Subject: sound layer, bouncing --- src/audio.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/audio.c (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c new file mode 100644 index 0000000..ed25d4c --- /dev/null +++ b/src/audio.c @@ -0,0 +1,28 @@ +#include "../include/audio.h" + +void play_sound(int channel, Mix_Chunk* wav) { + Mix_PlayChannel(channel, wav, 0); +} + +void play_positioned_sound(int channel, Mix_Chunk* wav, vec3f pos, float max_audible_dist) { + player* p = get_player_by_id(player_id); + if (!p) return; + + // calculate volume + int tiles_between_throwable_and_player = distance_between_3f((vec3f){.x = p->playerx, .y = p->playery, .z = p->height}, pos); + float volume = (tiles_between_throwable_and_player / max_audible_dist); + if (volume > 1.0f) volume = 1.0f; + + // calculate angle + /* + float dirx = (throwables[i].position.x - p->playerx); + float diry = (throwables[i].position.y - p->playery); + float rads = atan2(diry, dirx) * 180.0f/M_PI; + if (rads < 0) rads = 360 + rads; + rads += 90; + if (rads > 360) rads -= 360; + */ + + Mix_SetPosition(0, 0, volume*255); + Mix_PlayChannel(channel, wav, 0); +} -- cgit v1.2.3-70-g09d2