diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2024-01-07 14:17:07 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2024-01-07 14:17:07 +0100 |
| commit | 79eb2237b94900941c35859875c4bae21fa4fff6 (patch) | |
| tree | e40d1b81f4659286503ca1ef2d57657c64e811d3 | |
| parent | 843440d1e382f909d066c82d2269df67251b35f9 (diff) | |
fix ui audio source pos
| -rw-r--r-- | include/audio.h | 1 | ||||
| -rw-r--r-- | include/math_helper.h | 1 | ||||
| -rw-r--r-- | src/audio.c | 5 | ||||
| -rw-r--r-- | src/math_helper.c | 4 | ||||
| -rw-r--r-- | src/zombies.c | 2 |
5 files changed, 11 insertions, 2 deletions
diff --git a/include/audio.h b/include/audio.h index 9ee0bfd..5199854 100644 --- a/include/audio.h +++ b/include/audio.h @@ -43,6 +43,7 @@ typedef struct t_audio_event { #define MAX_AUDIO_EVENTS (NUM_AUDIO_CHANNELS) audio_event audio_events[MAX_AUDIO_EVENTS] = {0}; int max_audio_events = MAX_AUDIO_EVENTS; +vec3f global_audio_source_position =(vec3f){-1,-1,-1}; void play_music(Mix_Music* music); void add_throwable_audio_event_to_queue(audio_event_type event, throwable_type throwable, u32 playerid, vec3f position); diff --git a/include/math_helper.h b/include/math_helper.h index cdb083f..bfbc1cd 100644 --- a/include/math_helper.h +++ b/include/math_helper.h @@ -20,5 +20,6 @@ box get_render_box_of_square(platform_window* window, vec3f position, vec3f size box get_box_of_square(vec3f position, vec3f size); vec3f get_center_of_square(vec3f position, vec3f size); bool rect_contains_point(vec2 point, vec2 tl, vec2 br); +bool vec3f_equals(vec3f p1, vec3f p2); #endif
\ No newline at end of file diff --git a/src/audio.c b/src/audio.c index 43a403d..e831f6b 100644 --- a/src/audio.c +++ b/src/audio.c @@ -35,7 +35,7 @@ void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f positi } void add_ui_audio_event_to_queue(audio_event_type event) { - add_object_audio_event_to_queue(event, OBJECT_NONE, -1, (vec3f){-1,-1,-1}); + add_object_audio_event_to_queue(event, OBJECT_NONE, -1, global_audio_source_position); } static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) { @@ -158,6 +158,8 @@ void play_positioned_sound(int channel, Mix_Chunk* wav, vec3f pos, float max_aud // calculate volume int tiles_between_throwable_and_player = distance_between_3f((vec3f){.x = p->playerx, .y = p->playery, .z = p->height}, pos); + if (vec3f_equals(pos, global_audio_source_position)) tiles_between_throwable_and_player = 0; // Global audio source. + float volume = (tiles_between_throwable_and_player / max_audible_dist); if (volume > 1.0f) volume = 1.0f; if (volume < 0.0f) volume = 0.0f; @@ -173,5 +175,6 @@ void play_positioned_sound(int channel, Mix_Chunk* wav, vec3f pos, float max_aud */ int c = Mix_PlayChannel(-1, wav, 0); + if (c == -1) log_info("Audio not playable because no channels are free"); Mix_SetPosition(c, 0, (int)(volume*255)); } diff --git a/src/math_helper.c b/src/math_helper.c index 900b8aa..cb38861 100644 --- a/src/math_helper.c +++ b/src/math_helper.c @@ -108,6 +108,10 @@ box get_box_of_square(vec3f position, vec3f size) { return (box){rendertl, rendertr, renderbl, renderbr, rendertl, rendertr, renderbl, renderbr}; } +bool vec3f_equals(vec3f p1, vec3f p2) { + return p1.x == p2.x && p1.y == p2.y && p1.z == p2.z; +} + box get_render_box_of_square_without_incline(platform_window* window, vec3f position, vec3f size) { map_info info = get_map_info(window); float render_x = (info.tile_width * position.x); diff --git a/src/zombies.c b/src/zombies.c index 8ebf1b1..aa108b3 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -434,7 +434,7 @@ void draw_zombies(platform_window* window) { renderer->render_rectangle(zombie_pos.x + (zombie_size/2) - (bar_w/2), zombie_pos.y - bar_h, bar_w*percentage, bar_h, rgb(100,0,0)); } - if (global_state.server) draw_path_of_zombie(window, o); + //if (global_state.server) draw_path_of_zombie(window, o); } } |
