From 8f18e43af77c7869f842a4cbc14035fafd228b4b Mon Sep 17 00:00:00 2001 From: Taevas Date: Sun, 30 Mar 2025 15:40:22 +0200 Subject: [PATCH] implement the new main menu into the actual game --- elements/player.tscn | 1 + index.tscn | 234 +++++------------------------------------- menus/main/area.tscn | 59 ++++++++--- menus/main/panel.tscn | 8 +- menus/menu.tscn | 18 +++- project.godot | 2 +- 6 files changed, 96 insertions(+), 226 deletions(-) diff --git a/elements/player.tscn b/elements/player.tscn index 6df684a..54b3132 100644 --- a/elements/player.tscn +++ b/elements/player.tscn @@ -96,6 +96,7 @@ spot_range = 50.0 collision_priority = 100.0 axis_lock_linear_z = true physics_material_override = SubResource("PhysicsMaterial_vumbr") +can_sleep = false contact_monitor = true [node name="CollisionShape3D" type="CollisionShape3D" parent="Sphere"] diff --git a/index.tscn b/index.tscn index 7c82b45..9c27b90 100644 --- a/index.tscn +++ b/index.tscn @@ -1,6 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://ccgnnif026wb4"] - -[ext_resource type="PackedScene" uid="uid://dtfybhftwfn00" path="res://levels/demo.tscn" id="1_356j3"] +[gd_scene load_steps=4 format=3 uid="uid://ccgnnif026wb4"] [sub_resource type="GDScript" id="GDScript_8n212"] script/source = "extends Node @@ -15,6 +13,7 @@ var levels = [ preload(\"res://levels/forest/level.tscn\"), preload(\"res://levels/night/level.tscn\"), ] +var area_resource = preload(\"res://menus/main/area.tscn\") func _ready() -> void: var os_name = OS.get_name() @@ -26,19 +25,25 @@ func _ready() -> void: $PauseMenu.hide() ## Add the version of the game and the name of the OS to the footer of the start menu if OS.has_feature(\"editor\"): - $StartMenu/VBoxContainer/MarginContainer2/Notice.text = \"dev \" - $StartMenu/VBoxContainer/MarginContainer2/Notice.text += \"build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + os_name + \")\" + $DevInfos.text = \"dev \" + $DevInfos.text += \"build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + os_name + \")\" + launch_area() + +func launch_area(): + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + var area := area_resource.instantiate() + area.connect(\"request_start\", start_game) + $Levels.add_child(area) ## Get all the levels that are currently being played! ## In theory, there should ever be only zero or one, ## but it turns out it's more simple to handle things by using Arrays. func get_current_levels() -> Array[Level]: - var children = $Levels.get_children(true) + var children := $Levels.get_children(true) var current_levels: Array[Level] = [] for child in children: if is_instance_of(child, Level): current_levels.push_back(child) - return current_levels func start_level(level_scene: PackedScene) -> void: @@ -74,10 +79,8 @@ func stop_level() -> void: func win_game() -> void: $VictoryScreen.show() await get_tree().create_timer(2).timeout - $StartMenu/AnimationPlayer.play_backwards(\"fadeout\") - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - await get_tree().create_timer(1).timeout - $StartMenu.modulate = Color(1,1,1,1) + launch_area() + $VictoryScreen.hide() func restart_level() -> void: if changing_level == false: @@ -110,25 +113,18 @@ func fullscreen_game() -> void: else: DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED) -func _on_btn_start_pressed() -> void: +func start_game() -> void: seconds_spent = 0.0 current_level_int = 0 - var current_levels = get_current_levels() + var current_levels = $Levels.get_children(true) for level in current_levels: level.queue_free() $Informations.show() - $StartMenu/AnimationPlayer.play(\"fadeout\") Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) start_level(levels[0]) -func _on_animation_player_animation_finished(_anim_name: StringName) -> void: - if $StartMenu.modulate == Color(1,1,1,1): - $StartMenu.show() - else: - $StartMenu.hide() - func update_timer(delta: float) -> void: if playing: seconds_spent += delta @@ -145,7 +141,8 @@ func _process(delta: float) -> void: func _unhandled_key_input(event: InputEvent) -> void: if event.is_pressed() and event is InputEventKey: - if $StartMenu.visible == false and changing_level == false: + var current_levels := get_current_levels() + if len(current_levels) and changing_level == false: if event.keycode == KEY_ESCAPE: pause_game() elif event.keycode == KEY_R: @@ -166,61 +163,6 @@ font_size = 160 outline_size = 20 outline_color = Color(0, 0, 0, 1) -[sub_resource type="LabelSettings" id="LabelSettings_0jegv"] -font_size = 32 -shadow_size = 2 -shadow_color = Color(0, 0, 0, 1) -shadow_offset = Vector2(0, 0) - -[sub_resource type="LabelSettings" id="LabelSettings_nbp4i"] -font_size = 24 -shadow_size = 2 -shadow_color = Color(0, 0, 0, 1) -shadow_offset = Vector2(0, 0) - -[sub_resource type="LabelSettings" id="LabelSettings_5jdmh"] -font_size = 20 -shadow_size = 2 -shadow_color = Color(0, 0, 0, 1) -shadow_offset = Vector2(0, 0) - -[sub_resource type="Animation" id="Animation_glb01"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:modulate") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Color(1, 1, 1, 1)] -} - -[sub_resource type="Animation" id="Animation_75r06"] -resource_name = "fadeout" -step = 0.5 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:modulate") -tracks/0/interp = 2 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)] -} - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_5cb2g"] -_data = { -&"RESET": SubResource("Animation_glb01"), -&"fadeout": SubResource("Animation_75r06") -} - [node name="Game" type="Node"] script = SubResource("GDScript_8n212") @@ -293,133 +235,6 @@ vertical_alignment = 1 [node name="Levels" type="Node" parent="."] -[node name="Demo" parent="Levels" instance=ExtResource("1_356j3")] - -[node name="StartMenu" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="ColorRect" type="ColorRect" parent="StartMenu"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -color = Color(0.522749, 0.477374, 0.510111, 0.501961) - -[node name="VBoxContainer" type="VBoxContainer" parent="StartMenu"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="Presentation" type="MarginContainer" parent="StartMenu/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -theme_override_constants/margin_left = 20 -theme_override_constants/margin_top = 20 -theme_override_constants/margin_right = 20 -theme_override_constants/margin_bottom = 20 - -[node name="VBoxContainer" type="VBoxContainer" parent="StartMenu/VBoxContainer/Presentation"] -layout_mode = 2 - -[node name="Title" type="Label" parent="StartMenu/VBoxContainer/Presentation/VBoxContainer"] -layout_mode = 2 -text = "DreamBall" -label_settings = SubResource("LabelSettings_0jegv") -horizontal_alignment = 1 - -[node name="Title2" type="Label" parent="StartMenu/VBoxContainer/Presentation/VBoxContainer"] -layout_mode = 2 -text = "A game about changing gravity to make a ball fly through the air" -label_settings = SubResource("LabelSettings_nbp4i") -horizontal_alignment = 1 - -[node name="MarginContainer" type="MarginContainer" parent="StartMenu/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -theme_override_constants/margin_left = 20 -theme_override_constants/margin_top = 20 -theme_override_constants/margin_right = 20 -theme_override_constants/margin_bottom = 20 - -[node name="HBoxContainer" type="HBoxContainer" parent="StartMenu/VBoxContainer/MarginContainer"] -layout_mode = 2 -size_flags_vertical = 3 - -[node name="Rules" type="VBoxContainer" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -alignment = 2 - -[node name="Label" type="Label" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Rules"] -layout_mode = 2 -text = "- Change the direction of the gravity with the ARROW KEYS" - -[node name="Label2" type="Label" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Rules"] -layout_mode = 2 -text = "- Keep LEFT SHIFT pressed to make the gravity stronger" - -[node name="Label3" type="Label" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Rules"] -layout_mode = 2 -text = "- Press ESCAPE to pause and unpause the game at any point" - -[node name="Label4" type="Label" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Rules"] -layout_mode = 2 -text = "- Press R to restart the current level from the beginning -(note that it won't reset the timer!)" - -[node name="Buttons" type="VBoxContainer" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -alignment = 2 - -[node name="Label5" type="Label" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons"] -layout_mode = 2 -text = "Do your best to make the ball go through all the rings!" -horizontal_alignment = 1 - -[node name="HBoxContainer" type="HBoxContainer" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons"] -layout_mode = 2 -theme_override_constants/separation = 20 -alignment = 1 - -[node name="Btn_Fullscreen" type="Button" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 4 -action_mode = 0 -text = "Toggle FULLSCREEN" - -[node name="Btn_Start" type="Button" parent="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 4 -text = "START the game!" - -[node name="MarginContainer2" type="MarginContainer" parent="StartMenu/VBoxContainer"] -layout_mode = 2 -theme_override_constants/margin_left = 20 -theme_override_constants/margin_top = 20 -theme_override_constants/margin_right = 20 -theme_override_constants/margin_bottom = 20 - -[node name="Notice" type="Label" parent="StartMenu/VBoxContainer/MarginContainer2"] -layout_mode = 2 -label_settings = SubResource("LabelSettings_5jdmh") -horizontal_alignment = 1 - -[node name="AnimationPlayer" type="AnimationPlayer" parent="StartMenu"] -libraries = { -&"": SubResource("AnimationLibrary_5cb2g") -} - [node name="PauseMenu" type="Control" parent="."] visible = false z_index = 2 @@ -472,9 +287,16 @@ layout_mode = 2 size_flags_vertical = 6 text = "QUIT game" -[connection signal="pressed" from="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer/Btn_Fullscreen" to="." method="fullscreen_game"] -[connection signal="pressed" from="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer/Btn_Start" to="." method="_on_btn_start_pressed"] -[connection signal="animation_finished" from="StartMenu/AnimationPlayer" to="." method="_on_animation_player_animation_finished"] +[node name="DevInfos" type="Label" parent="."] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -23.0 +grow_horizontal = 2 +grow_vertical = 0 +horizontal_alignment = 1 + [connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Resume" to="." method="pause_game"] [connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Fullscreen2" to="." method="fullscreen_game"] [connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Restart" to="." method="restart_level"] diff --git a/menus/main/area.tscn b/menus/main/area.tscn index d7a6b56..152be3f 100644 --- a/menus/main/area.tscn +++ b/menus/main/area.tscn @@ -1,37 +1,45 @@ -[gd_scene load_steps=7 format=3 uid="uid://ikeidrgprk8k"] +[gd_scene load_steps=10 format=3 uid="uid://ikeidrgprk8k"] [ext_resource type="PackedScene" uid="uid://wlhsarkeqe8r" path="res://menus/main/panel.tscn" id="1_qfa5o"] +[ext_resource type="PackedScene" uid="uid://cnnvwotv33u1b" path="res://elements/player.tscn" id="2_0jxef"] [sub_resource type="GDScript" id="GDScript_bt14i"] script/source = "extends Node3D +signal request_start + var start_menu = preload(\"res://menus/main/start_menu.tscn\") var save_file_manager = preload(\"res://menus/main/save_file_manager.tscn\") var settings_menu = preload(\"res://menus/main/settings_menu.tscn\") func _ready() -> void: + $Menus/Panel2.connect(\"request_return\", func(): rotate_cube_to(0)) + $Menus/Panel3.connect(\"request_return\", func(): rotate_cube_to(90)) + $Menus/Panel4.connect(\"request_return\", func(): rotate_cube_to(180)) + var sm = start_menu.instantiate() sm.connect(\"request_start\", start) sm.connect(\"request_settings\", settings) - $Menus/Panel1.change_menu(sm) + $Menus/Panel1.change_menu(sm, false) func start() -> void: - var svm = save_file_manager.instantiate() - $Menus/Panel2.change_menu(svm) - rotate_cube(90) + request_start.emit() + #var svm = save_file_manager.instantiate() + #$Menus/Panel2.change_menu(svm) + #rotate_cube_to(90) func settings() -> void: var sm = settings_menu.instantiate() $Menus/Panel2.change_menu(sm) - rotate_cube(90) + rotate_cube_to(90) -func rotate_cube(degrees: int) -> void: +func rotate_cube_to(degrees: int) -> void: if $Menus/AnimationPlayer.is_playing(): return degrees = -degrees var animation: Animation = $Menus/AnimationPlayer.get_animation(\"rotate\") - var new_rotation = $Menus.rotation_degrees + Vector3(0, degrees, 0) + var new_rotation = Vector3(0, degrees, 0) animation.track_set_key_value(0, 0, $Menus.rotation_degrees) animation.track_set_key_value(0, 1, new_rotation) @@ -76,18 +84,26 @@ _data = { &"rotate": SubResource("Animation_bt14i") } +[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_bt14i"] +ground_color = Color(0.794232, 0.673177, 0.531056, 1) + +[sub_resource type="Sky" id="Sky_0jxef"] +sky_material = SubResource("PhysicalSkyMaterial_bt14i") + [sub_resource type="Environment" id="Environment_qfa5o"] -background_mode = 1 +background_mode = 2 background_color = Color(0.804743, 0.804743, 0.804743, 1) +sky = SubResource("Sky_0jxef") +ambient_light_source = 3 +ambient_light_color = Color(0.986752, 0.986752, 0.986752, 1) +reflected_light_source = 2 [node name="Area" type="Node3D"] process_mode = 3 script = SubResource("GDScript_bt14i") -[node name="SpotLight3D" type="SpotLight3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1.90692, 0) - [node name="Menus" type="CSGBox3D" parent="."] +use_collision = true [node name="Panel1" parent="Menus" instance=ExtResource("1_qfa5o")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.501) @@ -107,7 +123,24 @@ libraries = { } [node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(0.975535, 0, 0.219846, 0, 1, 0, -0.219846, 0, 0.975535, 0.86618, 0.217345, 1.76032) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.5) +current = true +fov = 40.0 [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_qfa5o") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.819152, -0.412596, 0.39844, 0, 0.694658, 0.71934, -0.573576, -0.589249, 0.569031, 0, 0, 0) + +[node name="Player" parent="." instance=ExtResource("2_0jxef")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.87335, 0) + +[node name="Camera" parent="Player" index="0"] +visible = false +current = false + +[node name="GPUParticles3D" parent="Player/Sphere" index="2"] +visible = false + +[editable path="Player"] diff --git a/menus/main/panel.tscn b/menus/main/panel.tscn index 04553cd..acadfdf 100644 --- a/menus/main/panel.tscn +++ b/menus/main/panel.tscn @@ -73,8 +73,11 @@ func _mouse_input_event(_camera: Camera3D, event: InputEvent, event_position: Ve # original code -func change_menu(new_menu: Control): - $SubViewport/Menu.add(new_menu) +signal request_return + +func change_menu(new_menu: Control, return_button: bool = true): + $SubViewport/Menu.add(new_menu, return_button) + $SubViewport/Menu.connect(\"disabled\", func(): request_return.emit()) " [sub_resource type="QuadMesh" id="QuadMesh_gfsnp"] @@ -85,7 +88,6 @@ viewport_path = NodePath("SubViewport") [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_a5lkq"] resource_local_to_scene = true transparency = 1 -shading_mode = 0 albedo_texture = SubResource("ViewportTexture_gfsnp") [sub_resource type="BoxShape3D" id="BoxShape3D_gfsnp"] diff --git a/menus/menu.tscn b/menus/menu.tscn index dddea27..bc66e2b 100644 --- a/menus/menu.tscn +++ b/menus/menu.tscn @@ -3,7 +3,9 @@ [sub_resource type="GDScript" id="GDScript_18a3y"] script/source = "extends MarginContainer -func add(node: Control): +signal disabled + +func add(node: Control, return_button: bool): var add_to := $VSplitContainer/MarginContainer/ColorRect var children := add_to.get_children(true) for child in children: @@ -16,8 +18,18 @@ func add(node: Control): add_to.add_child(node) $VSplitContainer/AnimationPlayer.play(\"split_offset\") - #await get_tree().create_timer(3.0).timeout - #$VSplitContainer/AnimationPlayer.play_backwards(\"split_offset\") + if return_button: + var button = Button.new() + button.text = \"Return\" + button.anchor_top = 1.0 + button.anchor_bottom = 1.0 + button.grow_vertical = Control.GROW_DIRECTION_BEGIN + button.connect(\"pressed\", disable) + node.add_child(button) + +func disable(): + $VSplitContainer/AnimationPlayer.play_backwards(\"split_offset\") + disabled.emit() " [sub_resource type="Animation" id="Animation_y8e4h"] diff --git a/project.godot b/project.godot index 3a26eb9..47b00e4 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="DreamBall" config/description="Manipulate the gravity to make a ball go through every ring! https://kitsunes.dev/Taevas/DreamBall" -config/version="20250326.0" +config/version="20250330.0" run/main_scene="res://index.tscn" config/features=PackedStringArray("4.4", "GL Compatibility") boot_splash/show_image=false