Rework elevator gameplay around pulse-blocking and per-floor spawning
This commit is contained in:
parent
a95eaa4dfb
commit
150e703d29
12 changed files with 423 additions and 151 deletions
|
|
@ -1,91 +1,171 @@
|
|||
extends Control
|
||||
# now we're cookin with bacon!
|
||||
extends PanelContainer
|
||||
|
||||
# Floor state
|
||||
var current_floor := 10
|
||||
var saved_count := 0
|
||||
var doors_closing := false
|
||||
var doors_closing_flag := false
|
||||
|
||||
# threshold increases as you descend!
|
||||
var base_threshold := 2
|
||||
var threshold_increase_interval := 2 # +1 required every x floors
|
||||
# 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
|
||||
|
||||
# scoring
|
||||
# Flat threshold: must save at least this many per floor
|
||||
var threshold := 2
|
||||
|
||||
# Scoring
|
||||
var score := 0
|
||||
var points_per_person := 100
|
||||
var points_per_person := 100 # base + bonus per person above threshold
|
||||
|
||||
# placeholder until henry's system provides real count
|
||||
var people_in_elevator := 3
|
||||
var people_in_elevator := 0
|
||||
|
||||
# placeholder until hnry's collision signal is ready
|
||||
# PLACEHOLDER: replaced by Henry's robot collision signal.
|
||||
# Handler is _on_timer_expired().
|
||||
var floor_time_limit := 10.0
|
||||
var floor_timer: Timer
|
||||
|
||||
func get_threshold() -> int:
|
||||
var floors_cleared := 10 - current_floor
|
||||
return base_threshold + floors_cleared / threshold_increase_interval
|
||||
# PLACEHOLDER: remove when Henry's spawning system is in.
|
||||
@onready var spawner = get_node("../../Node3D")
|
||||
|
||||
signal floor_changed(floor_num: int)
|
||||
signal saved_changed(count: int)
|
||||
signal score_changed(new_score: int)
|
||||
signal people_changed(count: int, threshold_val: int)
|
||||
signal game_won
|
||||
signal game_lost
|
||||
|
||||
func _ready():
|
||||
$PanelMargin/PanelColumn/CloseButton.pressed.connect(_on_close_pressed)
|
||||
var button = $PanelMargin/PanelColumn/CloseButton
|
||||
button.text = "BLOCK"
|
||||
button.pressed.connect(_on_block_pressed)
|
||||
|
||||
floor_timer = Timer.new()
|
||||
floor_timer.one_shot = true
|
||||
floor_timer.wait_time = floor_time_limit
|
||||
floor_timer.timeout.connect(_on_timer_expired)
|
||||
add_child(floor_timer)
|
||||
floor_timer.start()
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.pulse_blocked.connect(_on_pulse_blocked)
|
||||
screen.doors_closing.connect(_on_doors_closing)
|
||||
|
||||
EventBus.floor_changed.emit(current_floor)
|
||||
EventBus.people_changed.emit(people_in_elevator, get_threshold())
|
||||
_start_floor()
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventKey and event.pressed and event.keycode == KEY_SPACE:
|
||||
_on_close_pressed()
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_SPACE:
|
||||
_on_block_pressed()
|
||||
|
||||
# --- Floor lifecycle ---
|
||||
|
||||
func _start_floor():
|
||||
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)
|
||||
|
||||
people_changed.emit(people_in_elevator, threshold)
|
||||
floor_changed.emit(current_floor)
|
||||
|
||||
# Spawn 3D survivors (placeholder)
|
||||
print("spawner: ", spawner, " survivors: ", survivors_remaining)
|
||||
if spawner:
|
||||
spawner.start_spawning(survivors_remaining)
|
||||
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.start()
|
||||
screen.launch_pulse() # first survivor arrives
|
||||
|
||||
# Floor timer (placeholder for robot collision)
|
||||
if has_node("FloorTimer"):
|
||||
$FloorTimer.queue_free()
|
||||
var timer = Timer.new()
|
||||
timer.name = "FloorTimer"
|
||||
timer.wait_time = floor_time_limit
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(_on_timer_expired)
|
||||
add_child(timer)
|
||||
timer.start()
|
||||
|
||||
# --- Input ---
|
||||
|
||||
func _on_block_pressed():
|
||||
if doors_closing_flag:
|
||||
return
|
||||
$PanelMargin/PanelColumn/Screen.attempt_block()
|
||||
|
||||
# --- Pulse callbacks ---
|
||||
|
||||
func _on_pulse_blocked():
|
||||
# This survivor made it in
|
||||
survivors_remaining -= 1
|
||||
people_in_elevator += 1
|
||||
people_changed.emit(people_in_elevator, threshold)
|
||||
|
||||
if survivors_remaining <= 0:
|
||||
# Everyone's in, close doors (auto-success)
|
||||
_on_doors_closing()
|
||||
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(),
|
||||
CONNECT_ONE_SHOT
|
||||
)
|
||||
|
||||
func _on_doors_closing():
|
||||
if doors_closing_flag:
|
||||
return
|
||||
doors_closing_flag = true
|
||||
|
||||
# Stop spawning (placeholder)
|
||||
if spawner:
|
||||
spawner.stop_spawning()
|
||||
|
||||
if has_node("FloorTimer"):
|
||||
$FloorTimer.stop()
|
||||
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
|
||||
# Lose: not enough people
|
||||
if people_in_elevator < threshold:
|
||||
screen.show_loss("TOO FEW")
|
||||
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
|
||||
|
||||
score_changed.emit(score)
|
||||
saved_changed.emit(saved_count)
|
||||
|
||||
current_floor -= 1
|
||||
|
||||
# Win: reached ground floor
|
||||
if current_floor <= 1:
|
||||
screen.show_win()
|
||||
floor_changed.emit(current_floor)
|
||||
game_won.emit()
|
||||
return
|
||||
|
||||
# Next floor after countdown
|
||||
screen.show_countdown()
|
||||
screen.shrink_block_zone()
|
||||
|
||||
var tween = create_tween()
|
||||
tween.tween_interval(2.0)
|
||||
tween.tween_callback(_start_floor)
|
||||
|
||||
# --- Timer (placeholder for robot collision) ---
|
||||
|
||||
func _on_timer_expired():
|
||||
if doors_closing:
|
||||
if doors_closing_flag:
|
||||
return
|
||||
doors_closing = true
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.show_loss("TOO LATE :[")
|
||||
EventBus.game_lost.emit()
|
||||
|
||||
func _on_close_pressed():
|
||||
if doors_closing:
|
||||
return
|
||||
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
var success = screen.attempt_hack()
|
||||
if success:
|
||||
doors_closing = true
|
||||
floor_timer.stop()
|
||||
|
||||
if people_in_elevator < get_threshold():
|
||||
screen.show_loss("TOO FEW :[[")
|
||||
EventBus.game_lost.emit()
|
||||
return
|
||||
|
||||
# base points per person, bonus for each person above threshold??
|
||||
var bonus: int = max(0, people_in_elevator - get_threshold()) * points_per_person
|
||||
score += people_in_elevator * points_per_person + bonus
|
||||
EventBus.score_changed.emit(score)
|
||||
|
||||
saved_count += people_in_elevator
|
||||
current_floor -= 1
|
||||
EventBus.saved_changed.emit(saved_count)
|
||||
EventBus.floor_changed.emit(current_floor)
|
||||
|
||||
if current_floor <= 1:
|
||||
screen.show_win()
|
||||
EventBus.game_won.emit()
|
||||
else:
|
||||
screen.show_countdown()
|
||||
var tween = create_tween()
|
||||
tween.tween_callback(func():
|
||||
screen.reset_hack()
|
||||
doors_closing = false
|
||||
people_in_elevator = 3 # placeholder
|
||||
EventBus.people_changed.emit(people_in_elevator, get_threshold())
|
||||
floor_timer.start()
|
||||
).set_delay(2.0)
|
||||
else:
|
||||
print("MISSED! AI is faster now!")
|
||||
doors_closing_flag = true
|
||||
# Stop spawning (placeholder)
|
||||
if spawner:
|
||||
spawner.stop_spawning()
|
||||
$PanelMargin/PanelColumn/Screen.show_loss("TOO LATE")
|
||||
game_lost.emit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue