-
Notifications
You must be signed in to change notification settings - Fork 4
/
PauseCtrl.gd
43 lines (34 loc) · 1022 Bytes
/
PauseCtrl.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extends Node
export(bool) var can_toggle_pause: bool = true
signal Restart
func _process(_delta):
if Input.is_action_just_pressed("pause"):
if !get_tree().paused:
pause()
else:
resume()
func pause():
if can_toggle_pause:
get_tree().set_deferred("paused", true)
$PauseMenu.visible = true
$PauseMenu/VBoxContainer/ResumeBtn.grab_focus()
func resume():
if can_toggle_pause:
get_tree().set_deferred("paused", false)
$PauseMenu.visible = false
func gameover():
pause()
$PauseMenu/VBoxContainer/GameOver.visible = true
$PauseMenu/VBoxContainer/RestartBtn.visible = true
$PauseMenu/VBoxContainer/ResumeBtn.visible = false
$PauseMenu/VBoxContainer/RestartBtn.grab_focus()
func _on_QuitBtn_button_down():
get_tree().quit()
func _on_ResumeBtn_button_down():
resume()
func _on_RestartBtn_button_down():
$PauseMenu/VBoxContainer/GameOver.visible = false
$PauseMenu/VBoxContainer/RestartBtn.visible = false
$PauseMenu/VBoxContainer/ResumeBtn.visible = true
emit_signal("Restart")
resume()