From a0f924ba7b68d39c929e4f30f98ee7c4b670b4a1 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 27 Sep 2020 22:37:03 -0400 Subject: [PATCH] Pause menu full function + wip on game over screen --- src/HUD/HUD.gd | 2 + src/Items/Coin.tscn | 5 +- src/Menu/GameOver.gd | 21 +++ src/Menu/GameOver.tscn | 345 ++++++++++++++++++++++++++++++++++++++++ src/Menu/PauseMenu.gd | 12 ++ src/Menu/PauseMenu.tscn | 2 + 6 files changed, 386 insertions(+), 1 deletion(-) create mode 100644 src/Menu/GameOver.gd create mode 100644 src/Menu/GameOver.tscn diff --git a/src/HUD/HUD.gd b/src/HUD/HUD.gd index e77e630..152237c 100644 --- a/src/HUD/HUD.gd +++ b/src/HUD/HUD.gd @@ -19,7 +19,9 @@ func _physics_process(delta: float) -> void: _pause_ref = PauseMenu.instance() _pause_ref.connect("dismissed", self,"_on_pause_menu_dismissed") add_child(_pause_ref) + get_tree().paused = true _paused = true func _on_pause_menu_dismissed(): _paused = false + get_tree().paused = false diff --git a/src/Items/Coin.tscn b/src/Items/Coin.tscn index 9b3187b..adb80c4 100644 --- a/src/Items/Coin.tscn +++ b/src/Items/Coin.tscn @@ -190,14 +190,17 @@ collision_layer = 16 script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] -position = Vector2( 0, -4 ) +position = Vector2( 0, -4.56314 ) texture = ExtResource( 1 ) vframes = 2 hframes = 6 +frame = 7 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] +visible = false position = Vector2( 0, -4 ) shape = SubResource( 1 ) +disabled = true [node name="AnimationPlayer" type="AnimationPlayer" parent="."] autoplay = "idle" diff --git a/src/Menu/GameOver.gd b/src/Menu/GameOver.gd new file mode 100644 index 0000000..f012bf9 --- /dev/null +++ b/src/Menu/GameOver.gd @@ -0,0 +1,21 @@ +extends Node2D + +signal dismissed + +func _ready() -> void: + $CanvasLayer/VBoxContainer/NewGameBtn.grab_focus() + +func _on_ExitToMainMenuBtn_pressed() -> void: + $AnimationPlayer.play_backwards("fade") + yield($AnimationPlayer, "animation_finished"); + var next_scene = load("res://src/Menu/MainMenu.tscn") + get_tree().change_scene_to(next_scene) + queue_free() + + +func _on_NewGameBtn_pressed() -> void: + $AnimationPlayer.play_backwards("fade") + yield($AnimationPlayer, "animation_finished"); + emit_signal("dismissed") + get_tree().reload_current_scene() + pass # Replace with function body. diff --git a/src/Menu/GameOver.tscn b/src/Menu/GameOver.tscn new file mode 100644 index 0000000..6c8bf17 --- /dev/null +++ b/src/Menu/GameOver.tscn @@ -0,0 +1,345 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/Theme/slkscr.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/SplashScreen/BLANK.png" type="Texture" id=2] +[ext_resource path="res://src/Menu/GameOver.gd" type="Script" id=3] +[ext_resource path="res://assets/Theme/menu_font.tres" type="DynamicFont" id=4] +[ext_resource path="res://src/Items/Coin.tscn" type="PackedScene" id=5] +[ext_resource path="res://assets/HUD/lifes_icon.png" type="Texture" id=6] + +[sub_resource type="DynamicFont" id=1] +size = 25 +outline_size = 1 +outline_color = Color( 0.741176, 0.113725, 0.113725, 0.776471 ) +font_data = ExtResource( 1 ) + +[sub_resource type="Animation" id=2] +resource_name = "fade" +tracks/0/type = "value" +tracks/0/path = NodePath("CanvasLayer/TextureRect:self_modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.3, 0.5 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0.752941 ), Color( 1, 1, 1, 0.752941 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("CanvasLayer/Label:self_modulate") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0, 0.3, 0.5 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("CanvasLayer/VBoxContainer:self_modulate") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"times": PoolRealArray( ), +"transitions": PoolRealArray( ), +"update": 0, +"values": [ ] +} +tracks/3/type = "value" +tracks/3/path = NodePath("CanvasLayer/VBoxContainer:modulate") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"times": PoolRealArray( 0, 0.3, 0.5 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] +} +tracks/4/type = "value" +tracks/4/path = NodePath("CanvasLayer/Scores/Coins:modulate") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/keys = { +"times": PoolRealArray( 0, 0.5, 0.7 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] +} +tracks/5/type = "value" +tracks/5/path = NodePath("CanvasLayer/Scores/Lifes:modulate") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/keys = { +"times": PoolRealArray( 0, 0.5, 0.7, 0.9 ), +"transitions": PoolRealArray( 1, 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] +} +tracks/6/type = "value" +tracks/6/path = NodePath("CanvasLayer/Scores/Totals:modulate") +tracks/6/interp = 1 +tracks/6/loop_wrap = true +tracks/6/imported = false +tracks/6/enabled = true +tracks/6/keys = { +"times": PoolRealArray( 0, 0.9, 1 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] +} +tracks/7/type = "value" +tracks/7/path = NodePath("CanvasLayer/VBoxContainer/NewGameBtn:disabled") +tracks/7/interp = 1 +tracks/7/loop_wrap = true +tracks/7/imported = false +tracks/7/enabled = true +tracks/7/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ true, false ] +} +tracks/8/type = "value" +tracks/8/path = NodePath("CanvasLayer/VBoxContainer/ExitToMainMenuBtn:disabled") +tracks/8/interp = 1 +tracks/8/loop_wrap = true +tracks/8/imported = false +tracks/8/enabled = true +tracks/8/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ true, false ] +} + +[node name="GameOver" type="Node2D"] +pause_mode = 2 +script = ExtResource( 3 ) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="TextureRect" type="TextureRect" parent="CanvasLayer"] +self_modulate = Color( 1, 1, 1, 0.752941 ) +margin_right = 40.0 +margin_bottom = 40.0 +texture = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="CanvasLayer"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -78.0 +margin_top = 25.0 +margin_right = 78.0 +margin_bottom = 26.0 +custom_fonts/font = SubResource( 1 ) +text = "Game over" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -17.0 +margin_top = 45.0 +margin_right = 214.0 +margin_bottom = 113.0 +alignment = 2 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/VBoxContainer"] +margin_top = 6.0 +margin_right = 231.0 +margin_bottom = 6.0 + +[node name="NewGameBtn" type="Button" parent="CanvasLayer/VBoxContainer"] +margin_top = 10.0 +margin_right = 231.0 +margin_bottom = 37.0 +custom_fonts/font = ExtResource( 4 ) +text = "New Game" + +[node name="ExitToMainMenuBtn" type="Button" parent="CanvasLayer/VBoxContainer"] +margin_top = 41.0 +margin_right = 231.0 +margin_bottom = 68.0 +custom_fonts/font = ExtResource( 4 ) +text = "Exit To Main Menu" + +[node name="Scores" type="Control" parent="CanvasLayer"] +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +margin_left = 31.0 +margin_top = -70.0 +margin_right = 31.0 +margin_bottom = 45.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Coins" type="Control" parent="CanvasLayer/Scores"] +anchor_right = 1.0 +margin_left = 20.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Coin" parent="CanvasLayer/Scores/Coins" instance=ExtResource( 5 )] +position = Vector2( 0, 11 ) +scale = Vector2( 3, 3 ) + +[node name="x" type="Label" parent="CanvasLayer/Scores/Coins"] +margin_left = 14.0 +margin_top = -5.0 +margin_right = 32.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "x" + +[node name="amount" type="Label" parent="CanvasLayer/Scores/Coins"] +margin_left = 64.0 +margin_top = -5.0 +margin_right = 106.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "500" + +[node name="=" type="Label" parent="CanvasLayer/Scores/Coins"] +margin_left = 192.0 +margin_top = -5.0 +margin_right = 210.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "=" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="score" type="Label" parent="CanvasLayer/Scores/Coins"] +margin_left = 274.0 +margin_top = -5.0 +margin_right = 330.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "5000" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Lifes" type="Control" parent="CanvasLayer/Scores"] +anchor_right = 1.0 +margin_left = 20.0 +margin_top = 46.0 +margin_bottom = 46.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Life" type="TextureRect" parent="CanvasLayer/Scores/Lifes"] +margin_left = -12.0 +margin_top = -10.0 +margin_right = 15.0 +margin_bottom = 20.0 +texture = ExtResource( 6 ) +stretch_mode = 5 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="x" type="Label" parent="CanvasLayer/Scores/Lifes"] +margin_left = 14.0 +margin_top = -5.0 +margin_right = 32.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "x" + +[node name="amount" type="Label" parent="CanvasLayer/Scores/Lifes"] +margin_left = 64.0 +margin_top = -5.0 +margin_right = 106.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "500" + +[node name="=" type="Label" parent="CanvasLayer/Scores/Lifes"] +margin_left = 192.0 +margin_top = -5.0 +margin_right = 210.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "=" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="score" type="Label" parent="CanvasLayer/Scores/Lifes"] +margin_left = 274.0 +margin_top = -5.0 +margin_right = 330.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "5000" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Totals" type="Control" parent="CanvasLayer/Scores"] +anchor_right = 1.0 +margin_left = 20.0 +margin_top = 94.0 +margin_bottom = 94.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="=" type="Label" parent="CanvasLayer/Scores/Totals"] +margin_left = 192.0 +margin_top = -5.0 +margin_right = 210.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "=" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="total" type="Label" parent="CanvasLayer/Scores/Totals"] +margin_left = 274.0 +margin_top = -5.0 +margin_right = 330.0 +margin_bottom = 16.0 +custom_fonts/font = ExtResource( 4 ) +text = "5000" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +autoplay = "fade" +anims/fade = SubResource( 2 ) + +[node name="Node2D" type="Node2D" parent="."] +[connection signal="pressed" from="CanvasLayer/VBoxContainer/NewGameBtn" to="." method="_on_NewGameBtn_pressed"] +[connection signal="pressed" from="CanvasLayer/VBoxContainer/ExitToMainMenuBtn" to="." method="_on_ExitToMainMenuBtn_pressed"] diff --git a/src/Menu/PauseMenu.gd b/src/Menu/PauseMenu.gd index e55ae5e..c11c899 100644 --- a/src/Menu/PauseMenu.gd +++ b/src/Menu/PauseMenu.gd @@ -8,6 +8,9 @@ func _ready() -> void: func dismiss()->void: _on_ResumeBtn_pressed() +func _input(event: InputEvent) -> void: + if Input.is_action_just_pressed("pause"): + _on_ResumeBtn_pressed() func _on_ResumeBtn_pressed() -> void: $AnimationPlayer.play_backwards("fade") @@ -21,5 +24,14 @@ func _on_ExitToMainMenuBtn_pressed() -> void: $AnimationPlayer.play_backwards("fade") yield($AnimationPlayer, "animation_finished"); var next_scene = load("res://src/Menu/MainMenu.tscn") + emit_signal("dismissed") get_tree().change_scene_to(next_scene) queue_free() + + +func _on_NewGameBtn_pressed() -> void: + $AnimationPlayer.play_backwards("fade") + yield($AnimationPlayer, "animation_finished"); + emit_signal("dismissed") + get_tree().reload_current_scene() + pass # Replace with function body. diff --git a/src/Menu/PauseMenu.tscn b/src/Menu/PauseMenu.tscn index e38f4cc..18c7ce4 100644 --- a/src/Menu/PauseMenu.tscn +++ b/src/Menu/PauseMenu.tscn @@ -64,6 +64,7 @@ tracks/3/keys = { } [node name="PauseMenu" type="Node2D"] +pause_mode = 2 script = ExtResource( 3 ) [node name="CanvasLayer" type="CanvasLayer" parent="."] @@ -134,4 +135,5 @@ text = "Exit To Main Menu" autoplay = "fade" anims/fade = SubResource( 2 ) [connection signal="pressed" from="CanvasLayer/VBoxContainer/ResumeBtn" to="." method="_on_ResumeBtn_pressed"] +[connection signal="pressed" from="CanvasLayer/VBoxContainer/NewGameBtn" to="." method="_on_NewGameBtn_pressed"] [connection signal="pressed" from="CanvasLayer/VBoxContainer/ExitToMainMenuBtn" to="." method="_on_ExitToMainMenuBtn_pressed"]