Wire elevator panel sfx and randomized chase music
Play SfxOpen on floor start, ding each blocked pulse, and close on the countdown into the next floor - start a randomized chase track per pulse (avoiding immediate repeats) and fade it out via tween on block or doors closing - Delay the auto-close after the final survivor by 0.25s so the ding doesn't collide with the close sound!
This commit is contained in:
parent
3bf436b7d2
commit
c2f2201c98
1 changed files with 39 additions and 3 deletions
|
|
@ -19,6 +19,14 @@ var points_per_person := 100 # base + bonus per person above threshold
|
|||
|
||||
var people_in_elevator := 0
|
||||
|
||||
const CHASE_SHORT_1 := preload("res://audio/Shortchase1.wav")
|
||||
const CHASE_SHORT_2 := preload("res://audio/Shortchase2.wav")
|
||||
const CHASE_MID := preload("res://audio/Midchase1.wav")
|
||||
const CHASE_LONG := preload("res://audio/Chase1.wav")
|
||||
const CHASE_TRACKS := [CHASE_SHORT_1, CHASE_SHORT_2, CHASE_MID, CHASE_LONG]
|
||||
var _last_chase: AudioStream = null
|
||||
var _chase_tween: Tween = null
|
||||
|
||||
func _ready():
|
||||
var button = $PanelMargin/PanelColumn/CloseButton
|
||||
button.text = "BLOCK"
|
||||
|
|
@ -38,6 +46,7 @@ func _unhandled_input(event):
|
|||
# --- Floor lifecycle ---
|
||||
|
||||
func _start_floor():
|
||||
$SfxOpen.play()
|
||||
doors_closing_flag = false
|
||||
people_in_elevator = 0
|
||||
|
||||
|
|
@ -51,6 +60,7 @@ func _start_floor():
|
|||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.start()
|
||||
screen.launch_pulse() # first survivor arrives
|
||||
_start_chase()
|
||||
|
||||
# --- Input ---
|
||||
|
||||
|
|
@ -62,14 +72,17 @@ func _on_block_pressed():
|
|||
# --- Pulse callbacks ---
|
||||
|
||||
func _on_pulse_blocked():
|
||||
_stop_chase()
|
||||
# This survivor made it in
|
||||
survivors_remaining -= 1
|
||||
people_in_elevator += 1
|
||||
$SfxDing.play()
|
||||
EventBus.people_changed.emit(people_in_elevator, threshold)
|
||||
|
||||
if survivors_remaining <= 0:
|
||||
# Everyone's in, close doors (auto-success)
|
||||
_on_doors_closing()
|
||||
# Everyone's in, close doors (auto-success). Brief delay so the
|
||||
# last ding doesn't collide with the close sound.
|
||||
get_tree().create_timer(0.25).timeout.connect(_on_doors_closing, CONNECT_ONE_SHOT)
|
||||
return
|
||||
|
||||
# More survivors approaching: launch next pulse after gap
|
||||
|
|
@ -78,7 +91,8 @@ func _on_pulse_blocked():
|
|||
get_tree().create_timer(gap).timeout.connect(
|
||||
func():
|
||||
if not doors_closing_flag:
|
||||
screen.launch_pulse(),
|
||||
screen.launch_pulse()
|
||||
_start_chase(),
|
||||
CONNECT_ONE_SHOT
|
||||
)
|
||||
|
||||
|
|
@ -87,6 +101,8 @@ func _on_doors_closing():
|
|||
return
|
||||
doors_closing_flag = true
|
||||
|
||||
_stop_chase()
|
||||
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
|
||||
# Lose: not enough people
|
||||
|
|
@ -114,9 +130,29 @@ func _on_doors_closing():
|
|||
return
|
||||
|
||||
# Next floor after countdown
|
||||
$SfxClose.play()
|
||||
screen.show_countdown()
|
||||
screen.shrink_block_zone()
|
||||
|
||||
var tween = create_tween()
|
||||
tween.tween_interval(2.0)
|
||||
tween.tween_callback(_start_floor)
|
||||
|
||||
func _start_chase():
|
||||
if _chase_tween and _chase_tween.is_valid():
|
||||
_chase_tween.kill()
|
||||
|
||||
var candidates: Array = CHASE_TRACKS.filter(func(s): return s != _last_chase)
|
||||
var stream: AudioStream = candidates[randi() % candidates.size()]
|
||||
_last_chase = stream
|
||||
|
||||
$SfxChase.stream = stream
|
||||
$SfxChase.volume_db = 0.0
|
||||
$SfxChase.play()
|
||||
|
||||
func _stop_chase():
|
||||
if _chase_tween and _chase_tween.is_valid():
|
||||
_chase_tween.kill()
|
||||
_chase_tween = create_tween()
|
||||
_chase_tween.tween_property($SfxChase, "volume_db", -80.0, 0.3)
|
||||
_chase_tween.tween_callback($SfxChase.stop)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue