diff --git a/draugnorak.nvgt b/draugnorak.nvgt index 3ce235b..089f7c1 100644 --- a/draugnorak.nvgt +++ b/draugnorak.nvgt @@ -376,6 +376,6 @@ void main() } // Audio Listener Update - update_listener_tile(x); + p.update_listener_1d(x); } } diff --git a/src/audio_utils.nvgt b/src/audio_utils.nvgt index ece530d..3a4685c 100644 --- a/src/audio_utils.nvgt +++ b/src/audio_utils.nvgt @@ -106,9 +106,9 @@ void update_sound_range_1d_tile(int slot, int range_tiles) int play_1d_with_volume_step(string sound_file, int listener_x, int sound_x, bool looping, float volume_step) { - int slot = p.play_1d(sound_file, to_audio_position(listener_x), to_audio_position(sound_x), looping); + int slot = p.play_1d(sound_file, listener_x, sound_x, looping); if (slot != -1) { - p.update_sound_positioning_values(slot, -1.0, to_audio_volume_step(volume_step), true); + p.update_sound_positioning_values(slot, -1.0, volume_step, true); } return slot; } diff --git a/src/combat.nvgt b/src/combat.nvgt index a3d0441..5c01814 100644 --- a/src/combat.nvgt +++ b/src/combat.nvgt @@ -161,7 +161,7 @@ void release_sling_attack(int player_x) { Tree@ tree = get_tree_at(check_x); if (tree != null && !tree.is_chopped) { // Stone hits tree but doesn't damage it - play_1d_tile("sounds/weapons/sling_hit.ogg", player_x, check_x, false); + p.play_1d("sounds/weapons/sling_hit.ogg", player_x, check_x, false); screen_reader_speak("Stone hit tree at " + check_x + ".", true); return; } @@ -179,11 +179,11 @@ void release_sling_attack(int player_x) { // Damage the correct enemy type if (hit_bandit) { damage_bandit_at(target_x, damage); - play_1d_tile("sounds/weapons/sling_hit.ogg", player_x, target_x, false); + p.play_1d("sounds/weapons/sling_hit.ogg", player_x, target_x, false); play_1d_with_volume_step("sounds/enemies/zombie_hit.ogg", player_x, target_x, false, BANDIT_SOUND_VOLUME_STEP); } else { damage_zombie_at(target_x, damage); - play_1d_tile("sounds/weapons/sling_hit.ogg", player_x, target_x, false); + p.play_1d("sounds/weapons/sling_hit.ogg", player_x, target_x, false); play_1d_with_volume_step("sounds/enemies/zombie_hit.ogg", player_x, target_x, false, ZOMBIE_SOUND_VOLUME_STEP); } } diff --git a/src/constants.nvgt b/src/constants.nvgt index d6ea3f2..a6e758c 100644 --- a/src/constants.nvgt +++ b/src/constants.nvgt @@ -93,12 +93,12 @@ const int BANDIT_WANDER_DIRECTION_CHANGE_MAX = 8000; const int AUDIO_TILE_SCALE = 10; const float AUDIO_PAN_STEP = 2.0; const float AUDIO_VOLUME_STEP = 3.0; -const int SNARE_SOUND_RANGE = 5; +const int SNARE_SOUND_RANGE = 2; const float SNARE_SOUND_VOLUME_STEP = 4.0; // More audible for locating snares const float SNARE_SOUND_PAN_STEP = 4.0; // Stronger pan for direction -const int SNARE_COLLECT_RANGE = 2; +const int SNARE_COLLECT_RANGE = 1; -const int FIRE_SOUND_RANGE = 6; +const int FIRE_SOUND_RANGE = 3; const float FIRE_SOUND_VOLUME_STEP = 5.0; // 30 dB over 6 tiles const int FIREPIT_SOUND_RANGE = 5; diff --git a/src/environment.nvgt b/src/environment.nvgt index 3e428b3..3a65381 100644 --- a/src/environment.nvgt +++ b/src/environment.nvgt @@ -40,10 +40,18 @@ class Tree { } void update() { - // Keep tree sound active so distance-based fade can work. + // Only play tree sound if not chopped and within 3 tiles distance if (!is_chopped) { - if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { - sound_handle = play_1d_tile("sounds/environment/tree.ogg", x, position, true); + int tree_distance = x - position; + if (tree_distance < 0) tree_distance = -tree_distance; + + if (tree_distance <= 3) { + if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { + sound_handle = p.play_1d("sounds/environment/tree.ogg", x, position, true); + } + } else if (sound_handle != -1) { + p.destroy_sound(sound_handle); + sound_handle = -1; } } else if (sound_handle != -1) { p.destroy_sound(sound_handle); @@ -195,7 +203,7 @@ void damage_tree(int target_x, int damage) { } // Play the falling sound at the tree's position - play_1d_tile("sounds/items/tree.ogg", x, target.position, false); + p.play_1d("sounds/items/tree.ogg", x, target.position, false); int sticks_dropped = random(1, 3); int vines_dropped = random(1, 2); diff --git a/src/world_state.nvgt b/src/world_state.nvgt index c1e0930..e195126 100644 --- a/src/world_state.nvgt +++ b/src/world_state.nvgt @@ -114,12 +114,19 @@ class WorldSnare { minute_timer.restart(); } - // Keep snare sound active so distance-based fade can work. - if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { - sound_handle = play_1d_tile("sounds/actions/set_snare.ogg", x, position, true); - if (sound_handle != -1) { - p.update_sound_positioning_values(sound_handle, SNARE_SOUND_PAN_STEP, to_audio_volume_step(SNARE_SOUND_VOLUME_STEP), true); + int snare_distance = x - position; + if (snare_distance < 0) snare_distance = -snare_distance; + + if (snare_distance <= SNARE_SOUND_RANGE) { + if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { + sound_handle = p.play_1d("sounds/actions/set_snare.ogg", x, position, true); + if (sound_handle != -1) { + p.update_sound_positioning_values(sound_handle, SNARE_SOUND_PAN_STEP, SNARE_SOUND_VOLUME_STEP, true); + } } + } else if (sound_handle != -1) { + p.destroy_sound(sound_handle); + sound_handle = -1; } // Every minute logic (only when active) @@ -211,13 +218,20 @@ class WorldFire { } } - // Keep fire sound active while burning so distance-based fade can work. + // Hard cutoff for fire sound. if (is_burning()) { - if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { - sound_handle = play_1d_tile("sounds/items/fire.ogg", x, position, true); - if (sound_handle != -1) { - p.update_sound_positioning_values(sound_handle, -1.0, to_audio_volume_step(FIRE_SOUND_VOLUME_STEP), true); + int fire_distance = x - position; + if (fire_distance < 0) fire_distance = -fire_distance; + if (fire_distance <= FIRE_SOUND_RANGE) { + if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { + sound_handle = p.play_1d("sounds/items/fire.ogg", x, position, true); + if (sound_handle != -1) { + p.update_sound_positioning_values(sound_handle, -1.0, FIRE_SOUND_VOLUME_STEP, true); + } } + } else if (sound_handle != -1) { + p.destroy_sound(sound_handle); + sound_handle = -1; } } } @@ -322,13 +336,13 @@ class WorldStream { // Keep stream sound active so distance-based fade can work. if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { - sound_handle = play_1d_tile("sounds/terrain/stream.ogg", x, sound_pos, true); + sound_handle = p.play_1d("sounds/terrain/stream.ogg", x, sound_pos, true); sound_position = sound_pos; if (sound_handle != -1) { - p.update_sound_positioning_values(sound_handle, -1.0, to_audio_volume_step(STREAM_SOUND_VOLUME_STEP), true); + p.update_sound_positioning_values(sound_handle, -1.0, STREAM_SOUND_VOLUME_STEP, true); } } else if (sound_position != sound_pos) { - update_sound_1d_tile(sound_handle, sound_pos); + p.update_sound_1d(sound_handle, sound_pos); sound_position = sound_pos; } } @@ -1186,13 +1200,13 @@ class MountainRange { // Keep nearest stream sound active so distance-based fade can work. if (nearest_stream != -1) { if (stream_sound_handle == -1 || !p.sound_is_active(stream_sound_handle)) { - stream_sound_handle = play_1d_tile("sounds/terrain/stream.ogg", x, nearest_stream, true); + stream_sound_handle = p.play_1d("sounds/terrain/stream.ogg", x, nearest_stream, true); stream_sound_position = nearest_stream; if (stream_sound_handle != -1) { - p.update_sound_positioning_values(stream_sound_handle, -1.0, to_audio_volume_step(MOUNTAIN_STREAM_VOLUME_STEP), true); + p.update_sound_positioning_values(stream_sound_handle, -1.0, MOUNTAIN_STREAM_VOLUME_STEP, true); } } else if (stream_sound_position != nearest_stream) { - update_sound_1d_tile(stream_sound_handle, nearest_stream); + p.update_sound_1d(stream_sound_handle, nearest_stream); stream_sound_position = nearest_stream; } }