fuzzyworld

godot-shooter / commit

Calculate the high score times only when the pause menu is shown, not when the game starts.

9bc01bd501613a34201c1b98ed2305d18435f728 · Pavel Safronov · 2023-11-17 09:38:00 -0800 · parents 16938031653f

Calculate the high score times only when the pause menu is shown, not when the game starts.
 actors/Player.gd | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/actors/Player.gd b/actors/Player.gd
index 64fd8bf..7ea7ba5 100644
--- a/actors/Player.gd
+++ b/actors/Player.gd
@@ -44,26 +44,12 @@ func _ready() -> void:
 	velocity= Vector2.UP * move_speed
 	weapon = Weapons.create_basic_gun()
 
-	var now = Time.get_datetime_dict_from_system()
 #	Utils.remove_user_settings()
 	settings = Utils.load_user_settings()
 	settings.save_user_settings()
 	pause_always_show_intro_check.pressed = settings.show_intro
 	if settings.show_intro:
-		get_tree().paused = true
-		intro_menu.visible = true
-	if settings.high_scores.size() > 0:
-		Utils.remove_all_children(scores_list)
-		settings.high_scores.sort_custom(self, "sort_high_scores")
-		var index = 0
-		for hs in settings.high_scores:
-			index += 1
-			var label = Label.new()
-			var date_dict = hs.date
-			var date_diff_secs = Utils.time_diff_secs(date_dict, now)
-			var date_diff = Utils.timespan_to_english(date_diff_secs)
-			label.text = "%s - %s points, %s" % [index, hs.score, date_diff]
-			scores_list.add_child(label)
+		show_intro()
 
 func _process(_delta: float) -> void:
 	if dead:
@@ -80,6 +66,10 @@ func _physics_process(_delta: float) -> void:
 	velocity = move_and_slide(velocity)
 	global_rotation = velocity.angle() + PI/2.0
 
+func show_intro() -> void:
+	get_tree().paused = true
+	intro_menu.visible = true
+
 func clear_radar():
 	radar_sprite.modulate = Color(1,1,1,0)
 	var children = radar_container.get_children()
@@ -215,6 +205,7 @@ func show_message(message: String, duration_seconds: int = 2) -> void:
 
 func _on_HUD_paused() -> void:
 	get_tree().paused = true
+	set_pause_menu_high_scores()
 	$UI/PauseMenu.show()
 	emit_signal("destination_set", null)
 
@@ -227,3 +218,18 @@ func _on_HUD_debug_signal() -> void:
 
 func sort_high_scores(a, b):
 	return (a as Settings.HighScore).score > (b as Settings.HighScore).score
+
+func set_pause_menu_high_scores() -> void:
+	if settings.high_scores.size() > 0:
+		Utils.remove_all_children(scores_list)
+		settings.high_scores.sort_custom(self, "sort_high_scores")
+		var index = 0
+		var now = Time.get_datetime_dict_from_system()
+		for hs in settings.high_scores:
+			index += 1
+			var label = Label.new()
+			var date_dict = hs.date
+			var date_diff_secs = Utils.time_diff_secs(date_dict, now)
+			var date_diff = Utils.timespan_to_english(date_diff_secs)
+			label.text = "%s - %s points, %s" % [index, hs.score, date_diff]
+			scores_list.add_child(label)