fuzzyworld

godot-shooter / commit

On the web, pause when escape is used.

fc64e16690d758775ca2cf8c22761166d8aa1f93 · Pavel Safronov · 2023-11-08 06:47:38 -0800 · parents 212b7b2549f6

On the web, pause when escape is used.
 HUD.gd     |  4 +++-
 World.gd   | 11 +++++++++--
 World.tscn |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/HUD.gd b/HUD.gd
index c858231..10275ab 100644
--- a/HUD.gd
+++ b/HUD.gd
@@ -4,6 +4,7 @@ const Utils = preload("res://Utils.gd")
 export var score = 0
 export var level = 1
 export var objective = "1/17"
+signal paused
 
 onready var label = $CanvasLayer/MessageLabel
 onready var animation_player = $AnimationPlayer
@@ -21,7 +22,8 @@ func _process(_delta: float) -> void:
 		if OS.get_name() == "OSX":
 			get_tree().quit()
 		else:
-			restart()
+			emit_signal("paused")
+#			restart()
 	if Input.is_action_just_pressed("restart"):
 		restart()
 
diff --git a/World.gd b/World.gd
index ab69107..9e2eaf0 100644
--- a/World.gd
+++ b/World.gd
@@ -86,8 +86,7 @@ func _input(event: InputEvent) -> void:
 
 func _process(_delta: float) -> void:
 	if Input.is_action_just_pressed("pause"):
-		get_tree().paused = true
-		$UI/PauseMenu.show()
+		pause()
 		return
 
 	$UI/HUD.objective = "%s / %s" % [completed_objectives, max_objectives]
@@ -125,6 +124,10 @@ func _process(_delta: float) -> void:
 		if is_too_far:
 			item.queue_free()
 
+func pause():
+	get_tree().paused = true
+	$UI/PauseMenu.show()
+
 func set_destination(event_pos: Vector2) -> void:
 	var mid = Vector2(width / 2.0, height / 2.0)
 	var pos = event_pos + $Player.position - mid
@@ -180,3 +183,7 @@ func _on_Game_over_button_pressed() -> void:
 func _on_Player_shield_changed(shield_active: bool) -> void:
 	var message = "Shield Activated" if shield_active else "Shield Lost!"
 	$UI/HUD.show_message(message)
+
+
+func _on_HUD_paused() -> void:
+	pause()
diff --git a/World.tscn b/World.tscn
index fc4bf60..6d6aa5c 100644
--- a/World.tscn
+++ b/World.tscn
@@ -147,6 +147,7 @@ antialiased = true
 
 [connection signal="body_entered" from="Destination" to="." method="_on_Destination_body_entered"]
 [connection signal="shield_changed" from="Player" to="." method="_on_Player_shield_changed"]
+[connection signal="paused" from="UI/HUD" to="." method="_on_HUD_paused"]
 [connection signal="pressed" from="UI/PauseMenu/Panel/VBoxContainer/Button" to="." method="_on_Button_pressed"]
 [connection signal="pressed" from="UI/GameFinishedMenu/Panel/VBoxContainer/Button" to="." method="_on_Game_over_button_pressed"]
 [connection signal="timeout" from="ShootTimer" to="." method="_on_ShootTimer_timeout"]