Move game signals to EventBus 🚌
This commit is contained in:
parent
eb6f24a389
commit
684e2ece59
4 changed files with 21 additions and 17 deletions
|
|
@ -20,13 +20,6 @@ var people_in_elevator := 3
|
|||
var floor_time_limit := 10.0
|
||||
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:
|
||||
var floors_cleared := 10 - current_floor
|
||||
return base_threshold + floors_cleared / threshold_increase_interval
|
||||
|
|
@ -41,8 +34,8 @@ func _ready():
|
|||
add_child(floor_timer)
|
||||
floor_timer.start()
|
||||
|
||||
floor_changed.emit(current_floor)
|
||||
people_changed.emit(people_in_elevator, get_threshold())
|
||||
EventBus.floor_changed.emit(current_floor)
|
||||
EventBus.people_changed.emit(people_in_elevator, get_threshold())
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventKey and event.pressed and event.keycode == KEY_SPACE:
|
||||
|
|
@ -54,7 +47,7 @@ func _on_timer_expired():
|
|||
doors_closing = true
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.show_loss("TOO LATE :[")
|
||||
game_lost.emit()
|
||||
EventBus.game_lost.emit()
|
||||
|
||||
func _on_close_pressed():
|
||||
if doors_closing:
|
||||
|
|
@ -68,22 +61,22 @@ func _on_close_pressed():
|
|||
|
||||
if people_in_elevator < get_threshold():
|
||||
screen.show_loss("TOO FEW :[[")
|
||||
game_lost.emit()
|
||||
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
|
||||
score_changed.emit(score)
|
||||
EventBus.score_changed.emit(score)
|
||||
|
||||
saved_count += people_in_elevator
|
||||
current_floor -= 1
|
||||
saved_changed.emit(saved_count)
|
||||
floor_changed.emit(current_floor)
|
||||
EventBus.saved_changed.emit(saved_count)
|
||||
EventBus.floor_changed.emit(current_floor)
|
||||
|
||||
if current_floor <= 1:
|
||||
screen.show_win()
|
||||
game_won.emit()
|
||||
EventBus.game_won.emit()
|
||||
else:
|
||||
screen.show_countdown()
|
||||
var tween = create_tween()
|
||||
|
|
@ -91,7 +84,7 @@ func _on_close_pressed():
|
|||
screen.reset_hack()
|
||||
doors_closing = false
|
||||
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()
|
||||
).set_delay(2.0)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ func _ready():
|
|||
$StatsColumn/PeopleLabel.text = "PEOPLE: 0/2"
|
||||
$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):
|
||||
$StatsColumn/FloorLabel.text = "FLOOR: " + str(floor_num)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue