From db865e2ab9d989c8a0e448b94660a0d3a9c2e281 Mon Sep 17 00:00:00 2001 From: tonydero Date: Mon, 28 Oct 2024 11:34:48 -0600 Subject: [PATCH] add simple main menu and persistence of zone time --- project.godot | 2 +- scenes/main_menu.tscn | 44 ++++++++++++++++++++++++++++++++++++++ scripts/Player.gd | 5 +++-- scripts/PlayerState.gd | 2 ++ scripts/combat_ui_scene.gd | 17 ++++++--------- scripts/main_menu.gd | 13 +++++++++++ 6 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 scenes/main_menu.tscn create mode 100644 scripts/main_menu.gd diff --git a/project.godot b/project.godot index ecbd51c..c6831ce 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Semi-Idle ARPG" -run/main_scene="res://scenes/combatUIScene.tscn" +run/main_scene="res://scenes/main_menu.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://assets/icon.svg" diff --git a/scenes/main_menu.tscn b/scenes/main_menu.tscn new file mode 100644 index 0000000..9321ae6 --- /dev/null +++ b/scenes/main_menu.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=2 format=3 uid="uid://de7bjfpfgrnuv"] + +[ext_resource type="Script" path="res://scripts/main_menu.gd" id="1_2lfxk"] + +[node name="MainMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_2lfxk") + +[node name="MenuButtons" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -68.5 +offset_top = -50.5 +offset_right = 68.5 +offset_bottom = 50.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PlayButton" type="Button" parent="MenuButtons"] +layout_mode = 2 +text = "Play +" + +[node name="TestButton" type="Button" parent="MenuButtons"] +layout_mode = 2 +text = "Test +" + +[node name="ExitButton" type="Button" parent="MenuButtons"] +layout_mode = 2 +text = "Exit" + +[connection signal="pressed" from="MenuButtons/PlayButton" to="." method="_on_play_button_pressed"] +[connection signal="pressed" from="MenuButtons/TestButton" to="." method="_on_test_button_pressed"] +[connection signal="pressed" from="MenuButtons/ExitButton" to="." method="_on_exit_button_pressed"] diff --git a/scripts/Player.gd b/scripts/Player.gd index 376bc07..072b5b3 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -60,10 +60,11 @@ func _update_player_health(change: int) -> void: if current_health <= 0: $PlayerHealthBar/PlayerHealthCurrent.text = str(0) $PlayerHealthBar.value = 0 + print("You died.") # TODO: change to scene transition after slowing for a couple seconds # Engine.time_scale = 0.0001 - print("You died.") - get_tree().paused = true + # get_tree().paused = true + get_tree().change_scene_to_file("res://scenes/main_menu.tscn") elif current_health >= max_health: $PlayerHealthBar/PlayerHealthCurrent.text = str(max_health) $PlayerHealthBar.value = max_health diff --git a/scripts/PlayerState.gd b/scripts/PlayerState.gd index 3adcda0..125edde 100644 --- a/scripts/PlayerState.gd +++ b/scripts/PlayerState.gd @@ -11,3 +11,5 @@ var max_health := constitution * 100 var max_resource := 100 var current_resource := max_resource var weapon_type: Globals.Weapon.WeaponType + +var zone_duration := 0 diff --git a/scripts/combat_ui_scene.gd b/scripts/combat_ui_scene.gd index df4256b..daf699c 100644 --- a/scripts/combat_ui_scene.gd +++ b/scripts/combat_ui_scene.gd @@ -10,9 +10,6 @@ var totalAreas := 0 var worldArea: WorldArea var currentAreaQuest: Quest -var start_zone_time: float -var start_area_time: float -var current_zone_duration: float var current_area_duration: float @@ -25,8 +22,7 @@ func _ready() -> void: SignalBus.quest_completed.connect(_on_quest_completed) _create_area() - start_zone_time = Time.get_unix_time_from_system() - start_area_time = Time.get_unix_time_from_system() + current_area_duration = 0 # func _process(_delta: float) -> void: @@ -50,7 +46,8 @@ func _on_button_test_pressed() -> void: func _on_button_exit_pressed() -> void: - get_tree().quit() + # get_tree().quit() + get_tree().change_scene_to_file("res://scenes/main_menu.tscn") func _go_next_area() -> void: @@ -68,7 +65,7 @@ func _go_next_area() -> void: # Globals.debug_print("gna new area created") # _continue_button_hide() Globals.fade_node(%UITop/ContinueButton, "out", 0.1) - start_area_time = Time.get_unix_time_from_system() + current_area_duration = 0 canContinue = false @@ -91,7 +88,7 @@ func _on_continue_button_pressed() -> void: func _on_clock_timer_timeout() -> void: var current_time = Time.get_unix_time_from_system() %SystemClock.text = Time.get_time_string_from_unix_time(current_time) - current_zone_duration = current_time - start_zone_time - %ZTVal.text = Globals.elapsed_time_format(Globals.elapsed_time(current_zone_duration)) - current_area_duration = current_time - start_area_time + PlayerState.zone_duration += 1 + %ZTVal.text = Globals.elapsed_time_format(Globals.elapsed_time(PlayerState.zone_duration)) + current_area_duration += 1 %ATVal.text = Globals.elapsed_time_format(Globals.elapsed_time(current_area_duration)) diff --git a/scripts/main_menu.gd b/scripts/main_menu.gd new file mode 100644 index 0000000..e3624dc --- /dev/null +++ b/scripts/main_menu.gd @@ -0,0 +1,13 @@ +extends Control + + +func _on_play_button_pressed() -> void: + get_tree().change_scene_to_file("res://scenes/combatUIScene.tscn") + + +func _on_exit_button_pressed() -> void: + get_tree().quit() + + +func _on_test_button_pressed() -> void: + pass # Replace with function body.