mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
feat(audio): add turbo engagement cue
This commit is contained in:
@@ -8,6 +8,7 @@ const MAX_INTENSITY := 1.0
|
||||
|
||||
var enabled := true
|
||||
var _engine_player: AudioStreamPlayer
|
||||
var _engine_turbo := false
|
||||
|
||||
|
||||
func bind_tree_buttons(root: Node) -> void:
|
||||
@@ -50,9 +51,13 @@ func play_goal() -> void:
|
||||
|
||||
func set_engine_state(thrust: float, turbo: bool) -> void:
|
||||
var amount := clamp_intensity(thrust)
|
||||
var rising_turbo := should_play_turbo_cue(_engine_turbo, turbo, amount)
|
||||
if not enabled or amount <= 0.01:
|
||||
stop_engine()
|
||||
return
|
||||
if rising_turbo:
|
||||
_play_tone(260.0, 0.16, 0.16)
|
||||
_engine_turbo = turbo
|
||||
if _engine_player == null or not is_instance_valid(_engine_player):
|
||||
_engine_player = AudioStreamPlayer.new()
|
||||
_engine_player.stream = _engine_stream()
|
||||
@@ -65,6 +70,7 @@ func set_engine_state(thrust: float, turbo: bool) -> void:
|
||||
func stop_engine() -> void:
|
||||
if _engine_player != null and is_instance_valid(_engine_player):
|
||||
_engine_player.stop()
|
||||
_engine_turbo = false
|
||||
|
||||
|
||||
static func engine_pitch(thrust: float, turbo: bool) -> float:
|
||||
@@ -77,6 +83,10 @@ static func engine_volume(thrust: float, turbo: bool) -> float:
|
||||
return clampf(0.015 + amount * 0.045 + (0.025 if turbo and amount > 0.01 else 0.0), 0.0, 0.1)
|
||||
|
||||
|
||||
static func should_play_turbo_cue(previous_turbo: bool, turbo: bool, thrust: float) -> bool:
|
||||
return turbo and not previous_turbo and clamp_intensity(thrust) > 0.01
|
||||
|
||||
|
||||
static func clamp_intensity(value: float) -> float:
|
||||
if not is_finite(value):
|
||||
return 0.0
|
||||
|
||||
@@ -32,3 +32,10 @@ func test_engine_mix_is_bounded_and_turbo_is_audible() -> void:
|
||||
assert_true(AudioManager.engine_pitch(1.0, true) > AudioManager.engine_pitch(1.0, false), "turbo raises engine pitch")
|
||||
assert_true(AudioManager.engine_volume(1.0, true) > AudioManager.engine_volume(1.0, false), "turbo raises engine volume")
|
||||
assert_true(AudioManager.engine_volume(100.0, true) <= 0.1, "engine volume remains bounded")
|
||||
|
||||
|
||||
func test_turbo_state_is_only_a_rising_edge_for_the_engine_cue() -> void:
|
||||
assert_true(AudioManager.should_play_turbo_cue(false, true, 0.8), "turbo engagement emits a cue")
|
||||
assert_true(not AudioManager.should_play_turbo_cue(true, true, 0.8), "held turbo does not retrigger")
|
||||
assert_true(not AudioManager.should_play_turbo_cue(false, true, 0.0), "turbo at idle thrust is silent")
|
||||
assert_true(not AudioManager.should_play_turbo_cue(false, false, 0.8), "ordinary thrust emits no turbo cue")
|
||||
|
||||
Reference in New Issue
Block a user