add ambient sounds

This commit is contained in:
Teatov 2024-10-07 03:07:29 +10:00
parent 705e861e3f
commit f910daab21
11 changed files with 128 additions and 4 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
!.gdignore
*.tmp
*.*~

BIN
assets/audio/ambient/ambient_1.ogg (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,19 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://xcflll7pg3ou"
path="res://.godot/imported/ambient_1.ogg-9dce9b12b9b553370aa400c3c144cfe3.oggvorbisstr"
[deps]
source_file="res://assets/audio/ambient/ambient_1.ogg"
dest_files=["res://.godot/imported/ambient_1.ogg-9dce9b12b9b553370aa400c3c144cfe3.oggvorbisstr"]
[params]
loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4

BIN
assets/audio/ambient/ambient_2.ogg (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,19 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://c00xm63xawjah"
path="res://.godot/imported/ambient_2.ogg-9fd262e07a9da4fd8af8e1e718d5f2a2.oggvorbisstr"
[deps]
source_file="res://assets/audio/ambient/ambient_2.ogg"
dest_files=["res://.godot/imported/ambient_2.ogg-9fd262e07a9da4fd8af8e1e718d5f2a2.oggvorbisstr"]
[params]
loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4

BIN
assets/audio/ambient/ambient_3.ogg (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,19 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://bk3pj7hspvmiy"
path="res://.godot/imported/ambient_3.ogg-3c3ea051c9a5d56729a6b7174c8100c9.oggvorbisstr"
[deps]
source_file="res://assets/audio/ambient/ambient_3.ogg"
dest_files=["res://.godot/imported/ambient_3.ogg-3c3ea051c9a5d56729a6b7174c8100c9.oggvorbisstr"]
[params]
loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4

14
default_bus_layout.tres Normal file
View File

@ -0,0 +1,14 @@
[gd_resource type="AudioBusLayout" load_steps=2 format=3 uid="uid://cunpi1eovxtlu"]
[sub_resource type="AudioEffectHighPassFilter" id="AudioEffectHighPassFilter_dfyge"]
resource_name = "HighPassFilter"
[resource]
bus/1/name = &"ambient"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
bus/1/effect/0/effect = SubResource("AudioEffectHighPassFilter_dfyge")
bus/1/effect/0/enabled = true

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=15 format=3 uid="uid://ceru75se7ifkb"]
[gd_scene load_steps=16 format=3 uid="uid://ceru75se7ifkb"]
[ext_resource type="Script" path="res://scripts/main_camera.gd" id="1_gnxhh"]
[ext_resource type="PackedScene" uid="uid://d4c6ujs1ra1ob" path="res://scenes/units/aphid.tscn" id="3_eh22j"]
[ext_resource type="PackedScene" uid="uid://c70rhvk2okkcu" path="res://scenes/ui/buy_ants.tscn" id="4_irvxk"]
[ext_resource type="PackedScene" uid="uid://davys5ol18oyo" path="res://scenes/ui/pause_menu.tscn" id="5_ljrsn"]
[ext_resource type="Script" path="res://scripts/ambient_audio.gd" id="7_413eh"]
[ext_resource type="PackedScene" uid="uid://clftjlaotf2g2" path="res://scenes/structures/anthill.tscn" id="7_f30w3"]
[ext_resource type="PackedScene" uid="uid://d8ut24fit87x" path="res://scenes/ui/anthill_info.tscn" id="8_ohyy4"]
@ -107,3 +108,8 @@ transform = Transform3D(1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152,
current = true
far = 200.0
script = ExtResource("1_gnxhh")
[node name="AmbientAudio" type="AudioStreamPlayer" parent="."]
process_mode = 3
bus = &"ambient"
script = ExtResource("7_413eh")

34
scripts/ambient_audio.gd Normal file
View File

@ -0,0 +1,34 @@
extends AudioStreamPlayer
const ZOOMED_IN_CUTOFF = 10000
const ZOOMED_OUT_CUTOFF = 10
var audio_1 := preload("res://assets/audio/ambient/ambient_1.ogg")
var audio_2 := preload("res://assets/audio/ambient/ambient_2.ogg")
var audio_3 := preload("res://assets/audio/ambient/ambient_3.ogg")
var streams: Array[AudioStream] = [audio_1, audio_2, audio_3]
var filter: AudioEffectHighPassFilter
@onready var main_camera: MainCamera = $/root/World/MainCamera
func _ready() -> void:
assert(main_camera != null, "main_camera missing!")
var bus_idx := AudioServer.get_bus_index(bus)
for effect_idx in AudioServer.get_bus_effect_count(bus_idx):
var effect := AudioServer.get_bus_effect(bus_idx, effect_idx)
if effect is AudioEffectHighPassFilter:
filter = effect
stream = streams.pick_random()
play()
func _process(_delta: float) -> void:
filter.cutoff_hz = lerp(
ZOOMED_IN_CUTOFF,
ZOOMED_OUT_CUTOFF,
main_camera.zoom_value,
)

View File

@ -1,4 +1,5 @@
extends Camera3D
class_name MainCamera
enum CameraState {
FREE,
@ -39,6 +40,8 @@ var state: CameraState = CameraState.FREE
var window_out_of_focus: bool = false
@onready var anthill: Anthill = $/root/World/Structures/Anthill
func _process(delta: float) -> void:
_handle_heading_to(delta)
@ -71,7 +74,7 @@ func _input(event: InputEvent) -> void:
zoom_raw = clamp(zoom_raw, 0, 1)
if event.is_action_pressed("reset_camera"):
head_to(Vector3.ZERO)
head_to(anthill.global_position)
func _notification(what: int) -> void:
@ -93,8 +96,8 @@ func head_to(to: Vector3, zoom: float = ZOOM_VALUE_DEFAULT) -> void:
func _handle_movement(delta: float) -> void:
if (
window_out_of_focus
or state != CameraState.FREE
window_out_of_focus
or state != CameraState.FREE
or CursorManager.disable_confinement
or SelectionManager.selecting
):