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!
158 lines
4.2 KiB
GDScript
158 lines
4.2 KiB
GDScript
extends PanelContainer
|
|
|
|
# Floor state
|
|
var current_floor := 10
|
|
var saved_count := 0
|
|
var doors_closing_flag := false
|
|
|
|
# Survivors per floor: more at top, fewer as you descend
|
|
var base_survivors := 2
|
|
var survivors_per_floor_increase := 1 # per floor above ground
|
|
var survivors_remaining := 0
|
|
|
|
# Flat threshold: must save at least this many per floor
|
|
var threshold := 2
|
|
|
|
# Scoring
|
|
var score := 0
|
|
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"
|
|
button.pressed.connect(_on_block_pressed)
|
|
|
|
var screen = $PanelMargin/PanelColumn/Screen
|
|
screen.pulse_blocked.connect(_on_pulse_blocked)
|
|
screen.doors_closing.connect(_on_doors_closing)
|
|
|
|
_start_floor()
|
|
|
|
func _unhandled_input(event):
|
|
if event is InputEventKey and event.pressed and not event.echo:
|
|
if event.keycode == KEY_SPACE:
|
|
_on_block_pressed()
|
|
|
|
# --- Floor lifecycle ---
|
|
|
|
func _start_floor():
|
|
$SfxOpen.play()
|
|
doors_closing_flag = false
|
|
people_in_elevator = 0
|
|
|
|
# More survivors on higher floors, fewer near the ground
|
|
var floors_remaining = current_floor - 1
|
|
survivors_remaining = base_survivors + (floors_remaining * survivors_per_floor_increase)
|
|
|
|
EventBus.people_changed.emit(people_in_elevator, threshold)
|
|
EventBus.floor_changed.emit(current_floor)
|
|
|
|
var screen = $PanelMargin/PanelColumn/Screen
|
|
screen.start()
|
|
screen.launch_pulse() # first survivor arrives
|
|
_start_chase()
|
|
|
|
# --- Input ---
|
|
|
|
func _on_block_pressed():
|
|
if doors_closing_flag:
|
|
return
|
|
$PanelMargin/PanelColumn/Screen.attempt_block()
|
|
|
|
# --- 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). 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
|
|
var screen = $PanelMargin/PanelColumn/Screen
|
|
var gap = screen.get_pulse_gap()
|
|
get_tree().create_timer(gap).timeout.connect(
|
|
func():
|
|
if not doors_closing_flag:
|
|
screen.launch_pulse()
|
|
_start_chase(),
|
|
CONNECT_ONE_SHOT
|
|
)
|
|
|
|
func _on_doors_closing():
|
|
if doors_closing_flag:
|
|
return
|
|
doors_closing_flag = true
|
|
|
|
_stop_chase()
|
|
|
|
var screen = $PanelMargin/PanelColumn/Screen
|
|
|
|
# Lose: not enough people
|
|
if people_in_elevator < threshold:
|
|
screen.show_loss("TOO FEW")
|
|
EventBus.game_lost.emit()
|
|
return
|
|
|
|
# Score this floor
|
|
var base_points = people_in_elevator * points_per_person
|
|
var bonus = max(0, people_in_elevator - threshold) * points_per_person
|
|
score += base_points + bonus
|
|
saved_count += people_in_elevator
|
|
|
|
EventBus.score_changed.emit(score)
|
|
EventBus.saved_changed.emit(saved_count)
|
|
|
|
current_floor -= 1
|
|
|
|
# Win: reached ground floor
|
|
if current_floor <= 1:
|
|
screen.show_win()
|
|
EventBus.floor_changed.emit(current_floor)
|
|
EventBus.game_won.emit()
|
|
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)
|