diff --git a/src/HUD/HUD.gd b/src/HUD/HUD.gd index e886bad..e77e630 100644 --- a/src/HUD/HUD.gd +++ b/src/HUD/HUD.gd @@ -2,9 +2,24 @@ extends CanvasLayer class_name HUD export var coins_amount:int = 0 +export var PauseMenu: PackedScene; onready var Lable = get_node("CoinsContainer/Label") - +var _paused = false; +var _pause_ref; func on_coin_collected(amount:int): coins_amount += amount Lable.text = str(coins_amount) + +func _physics_process(delta: float) -> void: + if Input.is_action_just_pressed("pause"): + if _paused: + _pause_ref.dismiss() + else: + _pause_ref = PauseMenu.instance() + _pause_ref.connect("dismissed", self,"_on_pause_menu_dismissed") + add_child(_pause_ref) + _paused = true + +func _on_pause_menu_dismissed(): + _paused = false diff --git a/src/HUD/HUD.tscn b/src/HUD/HUD.tscn index 3061011..f465e8b 100644 --- a/src/HUD/HUD.tscn +++ b/src/HUD/HUD.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://src/HUD/HUD.gd" type="Script" id=1] +[ext_resource path="res://src/Menu/PauseMenu.tscn" type="PackedScene" id=2] [ext_resource path="res://assets/Theme/Theme.tres" type="Theme" id=3] [ext_resource path="res://assets/HUD/coins_hud.png" type="Texture" id=4] [node name="HUD" type="CanvasLayer"] script = ExtResource( 1 ) +PauseMenu = ExtResource( 2 ) [node name="CoinsContainer" type="HBoxContainer" parent="."] margin_left = 18.0 diff --git a/src/Levels/LevelTemplate/LevelTemplate.gd b/src/Levels/LevelTemplate/LevelTemplate.gd index 3cc7ee7..22d9628 100644 --- a/src/Levels/LevelTemplate/LevelTemplate.gd +++ b/src/Levels/LevelTemplate/LevelTemplate.gd @@ -9,8 +9,6 @@ var latest_checkpoint:CheckPoint = null func _physics_process(delta: float) -> void: - if Input.is_action_just_pressed("pause"): - get_tree().quit(0) _update_camera(delta) func _ready() -> void: diff --git a/src/Menu/MainMenu.tscn b/src/Menu/MainMenu.tscn index 9e27ce1..13bcc17 100644 --- a/src/Menu/MainMenu.tscn +++ b/src/Menu/MainMenu.tscn @@ -21,7 +21,7 @@ tracks/0/imported = false tracks/0/enabled = true tracks/0/keys = { "times": PoolRealArray( 0, 3, 6 ), -"transitions": PoolRealArray( 1, 0.277392, 0.435275 ), +"transitions": PoolRealArray( 0.450625, 0.277392, 0.435275 ), "update": 0, "values": [ Vector2( 73, 131 ), Vector2( 63.25, 154.25 ), Vector2( 73, 131 ) ] } @@ -98,10 +98,10 @@ texture = ExtResource( 1 ) centered = false [node name="Light2D" type="Light2D" parent="Node2D/Sprite"] -position = Vector2( 72.8142, 131.443 ) +position = Vector2( 69.75, 138.75 ) scale = Vector2( 12.3889, 12.3889 ) texture = ExtResource( 3 ) -color = Color( 0.976471, 0.515686, 0.505882, 1 ) +color = Color( 0.976471, 0.670588, 0.503922, 1 ) [node name="Sprite2" type="Sprite" parent="Node2D"] light_mask = -2147483646 @@ -110,7 +110,7 @@ texture = ExtResource( 4 ) centered = false [node name="Light2D2" type="Light2D" parent="Node2D/Sprite2"] -position = Vector2( 104.814, 154.943 ) +position = Vector2( 101.75, 162.25 ) scale = Vector2( 12.3889, 12.3889 ) texture = ExtResource( 3 ) color = Color( 0.762092, 0.913725, 0.398693, 1 ) diff --git a/src/Menu/PauseMenu.gd b/src/Menu/PauseMenu.gd new file mode 100644 index 0000000..e55ae5e --- /dev/null +++ b/src/Menu/PauseMenu.gd @@ -0,0 +1,25 @@ +extends Node2D + +signal dismissed + +func _ready() -> void: + $CanvasLayer/VBoxContainer/ResumeBtn.grab_focus() + +func dismiss()->void: + _on_ResumeBtn_pressed() + + +func _on_ResumeBtn_pressed() -> void: + $AnimationPlayer.play_backwards("fade") + yield($AnimationPlayer, "animation_finished"); + emit_signal("dismissed") + queue_free() + pass # Replace with function body. + + +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() diff --git a/src/Menu/PauseMenu.tscn b/src/Menu/PauseMenu.tscn new file mode 100644 index 0000000..e38f4cc --- /dev/null +++ b/src/Menu/PauseMenu.tscn @@ -0,0 +1,137 @@ +[gd_scene load_steps=7 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/PauseMenu.gd" type="Script" id=3] +[ext_resource path="res://assets/Theme/menu_font.tres" type="DynamicFont" id=4] + +[sub_resource type="DynamicFont" id=1] +size = 25 +outline_size = 1 +outline_color = Color( 0.427451, 0.729412, 0.745098, 0.776471 ) +font_data = ExtResource( 1 ) + +[sub_resource type="Animation" id=2] +resource_name = "fade" +length = 0.5 +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 ) ] +} + +[node name="PauseMenu" type="Node2D"] +script = ExtResource( 3 ) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="TextureRect" type="TextureRect" parent="CanvasLayer"] +self_modulate = Color( 1, 1, 1, 0 ) +margin_right = 40.0 +margin_bottom = 40.0 +texture = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="CanvasLayer"] +self_modulate = Color( 1, 1, 1, 0 ) +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -64.5 +margin_top = 32.0 +margin_right = 64.5 +margin_bottom = 58.0 +custom_fonts/font = SubResource( 1 ) +text = "Pause" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer"] +modulate = Color( 1, 1, 1, 0 ) +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -115.0 +margin_top = -46.0 +margin_right = 116.0 +margin_bottom = 124.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/VBoxContainer"] +margin_right = 231.0 + +[node name="ResumeBtn" type="Button" parent="CanvasLayer/VBoxContainer"] +margin_top = 4.0 +margin_right = 231.0 +margin_bottom = 31.0 +custom_fonts/font = ExtResource( 4 ) +text = "Resume" + +[node name="NewGameBtn" type="Button" parent="CanvasLayer/VBoxContainer"] +margin_top = 35.0 +margin_right = 231.0 +margin_bottom = 62.0 +custom_fonts/font = ExtResource( 4 ) +text = "New Game" + +[node name="ExitToMainMenuBtn" type="Button" parent="CanvasLayer/VBoxContainer"] +margin_top = 66.0 +margin_right = 231.0 +margin_bottom = 93.0 +custom_fonts/font = ExtResource( 4 ) +text = "Exit To Main Menu" + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +autoplay = "fade" +anims/fade = SubResource( 2 ) +[connection signal="pressed" from="CanvasLayer/VBoxContainer/ResumeBtn" to="." method="_on_ResumeBtn_pressed"] +[connection signal="pressed" from="CanvasLayer/VBoxContainer/ExitToMainMenuBtn" to="." method="_on_ExitToMainMenuBtn_pressed"]