A8: Synthesized sound effects and an adaptive score
Every sound is made by scripts in tools/audio/ and committed as a WAV in assets/audio/ with a manifest of hashes and levels: - dsp.gd: seeded noise, wavetable oscillators, filters, envelopes and struck modes. recipes.gd: 50 effects (footsteps on five surfaces, a report per weapon, impacts, carpentry building and breaking, the tide's bell, foghorn, surge and lighthouse, player, ambience, menus). - score.gd: an original eight-bar tune and chords in D Dorian, 6/8, rendered as four looping layers (drone, frame drum, concertina, fiddle). - loudness.gd and check.gd: per-category loudness targets, a -1 dBFS peak ceiling and the mix order (the tide loudest). make audio and make audio-check. In the client, SoundDirector turns FX records, footsteps, building, the tide and the player's own hurts into sounds, placed on 3D voices at the event so gunfire and footsteps come from their direction. MusicDirector fades the score's layers with the tide on an AudioStreamSynchronized, full in menus. MenuSounds knocks for buttons. Closes #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
## Wooden knocks for the menus: a soft tick when a button is pointed at or focused, a
|
||||
## peg knocked home when it's pressed, a two-step knock for going back. Attached to a
|
||||
## Control, it hooks every button under it, including ones made later (the server list).
|
||||
class_name MenuSounds
|
||||
extends Node
|
||||
|
||||
const BACK_WORDS: Array[String] = ["Back", "Resume", "Leave", "Cancel"]
|
||||
|
||||
## Sounds played since attached, newest last: for tests.
|
||||
var heard: Array[String] = []
|
||||
var audible: bool = true
|
||||
|
||||
var _root: Control
|
||||
var _voice: AudioStreamPlayer
|
||||
|
||||
|
||||
func attach(root: Control) -> void:
|
||||
_root = root
|
||||
SoundBank.ensure_bus(SoundBank.EFFECTS_BUS)
|
||||
_voice = AudioStreamPlayer.new()
|
||||
_voice.bus = SoundBank.EFFECTS_BUS
|
||||
_voice.max_polyphony = 4
|
||||
add_child(_voice)
|
||||
_hook_all(root)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().node_added.connect(_hook_later)
|
||||
|
||||
|
||||
func _hook_later(node: Node) -> void:
|
||||
if _root != null and (node == _root or _root.is_ancestor_of(node)):
|
||||
_hook(node)
|
||||
|
||||
|
||||
func _hook_all(node: Node) -> void:
|
||||
_hook(node)
|
||||
for child: Node in node.get_children():
|
||||
_hook_all(child)
|
||||
|
||||
|
||||
func _hook(node: Node) -> void:
|
||||
var button: BaseButton = node as BaseButton
|
||||
if button == null or button.has_meta("menu_sounds"):
|
||||
return
|
||||
button.set_meta("menu_sounds", true)
|
||||
var text: String = (button as Button).text if button is Button else ""
|
||||
var press: String = "ui_back" if BACK_WORDS.has(text) else "ui_click"
|
||||
button.pressed.connect(play.bind(press))
|
||||
button.mouse_entered.connect(play.bind("ui_hover"))
|
||||
button.focus_entered.connect(play.bind("ui_hover"))
|
||||
|
||||
|
||||
func play(sound: String) -> void:
|
||||
heard.append(sound)
|
||||
if heard.size() > 64:
|
||||
heard.pop_front()
|
||||
if not audible or _voice == null:
|
||||
return
|
||||
_voice.stream = SoundBank.stream(sound)
|
||||
_voice.play()
|
||||
Reference in New Issue
Block a user