Skip to content

Commit 008840b

Browse files
dariocavadawjt
andauthored
Pause timer before game starts & after game is won (#26)
Adjusted `global.gd` and `hud.gd` to properly manage timer behavior according to the time limit setting. Fixes #25 --------- Co-authored-by: Will Thompson <wjt@endlessos.org>
1 parent 28b7bb2 commit 008840b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

scripts/global.gd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ signal coin_collected
55
signal flag_raised(flag: Flag)
66
signal lives_changed
77
signal game_ended(ending: Endings)
8+
signal game_started
89

910
## Emitted by [GameLogic] when the world's gravitational force is changed.
1011
@warning_ignore("unused_signal")
@@ -41,6 +42,7 @@ func setup_timer(time_limit: int):
4142
timer.timeout.connect(_on_timer_timeout)
4243
add_child(timer)
4344
timer.start(time_limit)
45+
timer.paused = true
4446
timer_added.emit()
4547

4648

@@ -55,3 +57,21 @@ func _set_lives(value):
5557
lives_changed.emit()
5658
if lives <= 0:
5759
game_ended.emit(Global.Endings.LOSE)
60+
61+
62+
func _ready():
63+
# Connect signals to handle game events.
64+
game_ended.connect(_on_game_ended)
65+
game_started.connect(_on_game_start)
66+
67+
68+
func _on_game_ended(_ending: Endings):
69+
# Pause the timer if it is running.
70+
if timer and not timer.is_stopped():
71+
timer.paused = true
72+
73+
74+
func _on_game_start():
75+
# Start the timer if it has been set up.
76+
if timer != null:
77+
timer.paused = false

scripts/hud.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func _ready():
2727
Input.joy_connection_changed.connect(_on_joy_connection_changed)
2828
if DisplayServer.is_touchscreen_available():
2929
%Start.hide()
30+
Global.game_started.emit()
3031

3132

3233
func _on_joy_connection_changed(index: int, connected: bool):
@@ -48,6 +49,7 @@ func _unhandled_input(event):
4849
and %Start.is_visible_in_tree()
4950
):
5051
%Start.hide()
52+
Global.game_started.emit()
5153

5254

5355
func _on_coin_collected():

0 commit comments

Comments
 (0)