fuzzyworld

godot-shooter / commit

Added intro screen that shows up before the game starts.

cac0fb4f60dfbf17a442639a2f7a39f7cb3f7e65 · Pavel Safronov · 2023-11-11 15:04:22 -0800 · parents c3ac3ecef022

Added intro screen that shows up before the game starts.
 HUD.gd     | 10 +++++++--
 HUD.tscn   |  1 +
 World.gd   |  9 +++++++-
 World.tscn | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/HUD.gd b/HUD.gd
index ebe8d99..c52f9e4 100644
--- a/HUD.gd
+++ b/HUD.gd
@@ -17,16 +17,21 @@ onready var ammo_label = $MarginContainer2/HBoxContainer/Ammo
 
 func _input(event: InputEvent) -> void:
 	var nodes = get_tree().get_nodes_in_group("pause_menu")
-	var pause_menu = nodes[0] as Control
-	var is_pause_menu_open = pause_menu.visible
+	var is_pause_menu_open = false
+	for n in nodes:
+		var node: Control = n
+		is_pause_menu_open = is_pause_menu_open or node.visible
 	if is_pause_menu_open:
 		return
 
 	if event is InputEventScreenTouch and event.pressed:
+		Utils.log("signal position_set - touch pressed", "position", event.position)
 		emit_signal("position_set", event.position)
 	if event is InputEventScreenDrag:
+		Utils.log("signal position_set - screen dragged", "position", event.position)
 		emit_signal("position_set", event.position)
 	if event is InputEventMouseButton:
+		Utils.log("signal position_set - mouse button", "pressed", event.pressed, "position", event.position)
 		if not is_dragging and event.pressed:
 			is_dragging = true
 			get_tree().paused = true
@@ -35,6 +40,7 @@ func _input(event: InputEvent) -> void:
 			is_dragging = false
 			get_tree().paused = false
 	if event is InputEventMouseMotion and is_dragging:
+		Utils.log("signal position_set - mouse motion", "position", event.position)
 		emit_signal("position_set", event.position)
 
 
diff --git a/HUD.tscn b/HUD.tscn
index e06310b..d0d033c 100644
--- a/HUD.tscn
+++ b/HUD.tscn
@@ -104,6 +104,7 @@ margin_bottom = 74.0
 [node name="PauseButton" type="Button" parent="MarginContainer/HBoxContainer2"]
 margin_right = 42.0
 margin_bottom = 74.0
+mouse_default_cursor_shape = 2
 text = "="
 
 [node name="Objective" type="Label" parent="MarginContainer/HBoxContainer2"]
diff --git a/World.gd b/World.gd
index 553be21..36fd295 100644
--- a/World.gd
+++ b/World.gd
@@ -88,7 +88,8 @@ func create_shield() -> PowerUp:
 	return shield
 
 func _ready() -> void:
-	$UI/HUD.show_message("Tap/drag to move")
+	get_tree().paused = true
+	$UI/IntroMenu.visible = true
 
 func get_new_item_pos(dist_ratio: float = 1.0) -> Vector2:
 	var pos_angle = randi() % 360
@@ -240,3 +241,9 @@ func _on_LinkButton_pressed() -> void:
 	get_tree().paused = true
 	var _err = OS.shell_open("https://gitlab.com/PavelSafronov/godot-shooter")
 	get_tree().paused = true
+
+
+func _on_StartButton_pressed() -> void:
+	get_tree().paused = false
+	$UI/IntroMenu.visible = false
+	get_tree().set_input_as_handled()
diff --git a/World.tscn b/World.tscn
index 5fb19d9..8b621c7 100644
--- a/World.tscn
+++ b/World.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=9 format=2]
+[gd_scene load_steps=13 format=2]
 
 [ext_resource path="res://assets/kenney_simple-space/PNG/Default/icon_crossLarge.png" type="Texture" id=1]
 [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
@@ -7,10 +7,24 @@
 [ext_resource path="res://StarField.tscn" type="PackedScene" id=5]
 [ext_resource path="res://CharacterTheme.tres" type="Theme" id=6]
 [ext_resource path="res://Theme.tres" type="Theme" id=7]
+[ext_resource path="res://assets/neuropolitical rg.otf" type="DynamicFontData" id=8]
 
 [sub_resource type="CircleShape2D" id=1]
 radius = 29.0172
 
+[sub_resource type="DynamicFont" id=2]
+size = 24
+font_data = ExtResource( 8 )
+
+[sub_resource type="DynamicFont" id=3]
+outline_color = Color( 0, 0.490196, 0.831373, 1 )
+use_mipmaps = true
+use_filter = true
+font_data = ExtResource( 8 )
+
+[sub_resource type="Theme" id=4]
+default_font = SubResource( 3 )
+
 [node name="World" type="Node2D"]
 script = ExtResource( 4 )
 
@@ -172,6 +186,60 @@ margin_right = 168.0
 margin_bottom = 194.0
 text = "Replay!"
 
+[node name="IntroMenu" type="Control" parent="UI" groups=["pause_menu"]]
+visible = false
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="CenterContainer" type="CenterContainer" parent="UI/IntroMenu"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="PanelContainer" type="PanelContainer" parent="UI/IntroMenu/CenterContainer"]
+margin_left = 236.0
+margin_top = 386.0
+margin_right = 264.0
+margin_bottom = 414.0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="UI/IntroMenu/CenterContainer/PanelContainer"]
+margin_left = 14.0
+margin_top = 14.0
+margin_right = 447.0
+margin_bottom = 395.0
+theme = ExtResource( 7 )
+alignment = 1
+
+[node name="Label" type="Label" parent="UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer"]
+margin_right = 433.0
+margin_bottom = 30.0
+custom_fonts/font = SubResource( 2 )
+text = "Welcome to Tactical Shooter!"
+
+[node name="RichTextLabel" type="RichTextLabel" parent="UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer"]
+margin_top = 38.0
+margin_right = 433.0
+margin_bottom = 324.0
+theme = SubResource( 4 )
+text = "This is a 2D space shooter game.
+
+You choose where to fly in this game.
+
+Your ship will attack for you.
+
+Touch/click + hold anywhere to pause the game and plan your course.
+Let go to set location as the destination.
+
+Your objective count is in the lower-right corner.
+The radar shows enemies and objectives."
+fit_content_height = true
+
+[node name="StartButton" type="Button" parent="UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer"]
+margin_top = 332.0
+margin_right = 433.0
+margin_bottom = 381.0
+mouse_default_cursor_shape = 2
+text = "Start Game"
+
 [node name="ShootTimer" type="Timer" parent="."]
 process_mode = 0
 wait_time = 0.05
@@ -195,4 +263,5 @@ antialiased = true
 [connection signal="position_set" from="UI/HUD" to="." method="set_destination"]
 [connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Src/LinkButton" to="." method="_on_LinkButton_pressed"]
 [connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"]
+[connection signal="pressed" from="UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer/StartButton" to="." method="_on_StartButton_pressed"]
 [connection signal="timeout" from="ShootTimer" to="." method="_on_ShootTimer_timeout"]