Move game signals to EventBus 🚌

This commit is contained in:
Jennie Robinson Faber 2026-05-09 19:04:33 +01:00
parent eb6f24a389
commit 684e2ece59
4 changed files with 21 additions and 17 deletions

View file

@ -20,13 +20,6 @@ var people_in_elevator := 3
var floor_time_limit := 10.0 var floor_time_limit := 10.0
var floor_timer: Timer var floor_timer: Timer
signal floor_changed(floor_num: int)
signal saved_changed(count: int)
signal score_changed(new_score: int)
signal people_changed(count: int, threshold: int)
signal game_won
signal game_lost
func get_threshold() -> int: func get_threshold() -> int:
var floors_cleared := 10 - current_floor var floors_cleared := 10 - current_floor
return base_threshold + floors_cleared / threshold_increase_interval return base_threshold + floors_cleared / threshold_increase_interval
@ -41,8 +34,8 @@ func _ready():
add_child(floor_timer) add_child(floor_timer)
floor_timer.start() floor_timer.start()
floor_changed.emit(current_floor) EventBus.floor_changed.emit(current_floor)
people_changed.emit(people_in_elevator, get_threshold()) EventBus.people_changed.emit(people_in_elevator, get_threshold())
func _unhandled_input(event): func _unhandled_input(event):
if event is InputEventKey and event.pressed and event.keycode == KEY_SPACE: if event is InputEventKey and event.pressed and event.keycode == KEY_SPACE:
@ -54,7 +47,7 @@ func _on_timer_expired():
doors_closing = true doors_closing = true
var screen = $PanelMargin/PanelColumn/Screen var screen = $PanelMargin/PanelColumn/Screen
screen.show_loss("TOO LATE :[") screen.show_loss("TOO LATE :[")
game_lost.emit() EventBus.game_lost.emit()
func _on_close_pressed(): func _on_close_pressed():
if doors_closing: if doors_closing:
@ -68,22 +61,22 @@ func _on_close_pressed():
if people_in_elevator < get_threshold(): if people_in_elevator < get_threshold():
screen.show_loss("TOO FEW :[[") screen.show_loss("TOO FEW :[[")
game_lost.emit() EventBus.game_lost.emit()
return return
# base points per person, bonus for each person above threshold?? # base points per person, bonus for each person above threshold??
var bonus: int = max(0, people_in_elevator - get_threshold()) * points_per_person var bonus: int = max(0, people_in_elevator - get_threshold()) * points_per_person
score += people_in_elevator * points_per_person + bonus score += people_in_elevator * points_per_person + bonus
score_changed.emit(score) EventBus.score_changed.emit(score)
saved_count += people_in_elevator saved_count += people_in_elevator
current_floor -= 1 current_floor -= 1
saved_changed.emit(saved_count) EventBus.saved_changed.emit(saved_count)
floor_changed.emit(current_floor) EventBus.floor_changed.emit(current_floor)
if current_floor <= 1: if current_floor <= 1:
screen.show_win() screen.show_win()
game_won.emit() EventBus.game_won.emit()
else: else:
screen.show_countdown() screen.show_countdown()
var tween = create_tween() var tween = create_tween()
@ -91,7 +84,7 @@ func _on_close_pressed():
screen.reset_hack() screen.reset_hack()
doors_closing = false doors_closing = false
people_in_elevator = 3 # placeholder people_in_elevator = 3 # placeholder
people_changed.emit(people_in_elevator, get_threshold()) EventBus.people_changed.emit(people_in_elevator, get_threshold())
floor_timer.start() floor_timer.start()
).set_delay(2.0) ).set_delay(2.0)
else: else:

View file

@ -6,6 +6,11 @@ func _ready():
$StatsColumn/PeopleLabel.text = "PEOPLE: 0/2" $StatsColumn/PeopleLabel.text = "PEOPLE: 0/2"
$StatsColumn/ScoreLabel.text = "SCORE: 0" $StatsColumn/ScoreLabel.text = "SCORE: 0"
EventBus.floor_changed.connect(update_floor)
EventBus.saved_changed.connect(update_saved)
EventBus.people_changed.connect(update_people)
EventBus.score_changed.connect(update_score)
func update_floor(floor_num: int): func update_floor(floor_num: int):
$StatsColumn/FloorLabel.text = "FLOOR: " + str(floor_num) $StatsColumn/FloorLabel.text = "FLOOR: " + str(floor_num)

View file

@ -2,5 +2,11 @@ extends Node
@warning_ignore_start("unused_signal") # since otherwise Godot will throw a warning that the signal is unused in current scope @warning_ignore_start("unused_signal") # since otherwise Godot will throw a warning that the signal is unused in current scope
signal floor_changed(floor_num: int)
signal saved_changed(count: int)
signal score_changed(new_score: int)
signal people_changed(count: int, threshold: int)
signal game_won
signal game_lost
@warning_ignore_restore("unused_signal") # put any future signals you add between the two ignore annotations @warning_ignore_restore("unused_signal") # put any future signals you add between the two ignore annotations