summaryrefslogtreecommitdiff
path: root/src/audio.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 10:52:18 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 10:52:18 +0200
commit18c1dfbb78d98516f5480f8199910fe41ac904df (patch)
tree8ee69fde44ac3b8969ebf529883656a2d05b1e45 /src/audio.c
parent641f81317a5b5cea6b3c5a4c65b1ca4313b0d8c0 (diff)
sound layer, bouncing
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c28
1 files changed, 28 insertions, 0 deletions
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);
+}