diff options
author | rom <romangraef@gmail.com> | 2021-04-26 13:24:19 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-26 13:24:19 +0200 |
commit | b66eb089dbce08f4d38df39f373718194febcb61 (patch) | |
tree | 727d457c82b9fe899edc7bb931672455b469fa4f /scenes | |
parent | 33609f3d9ac89116e23eb561c027b04c9658e242 (diff) | |
download | ldjam48-b66eb089dbce08f4d38df39f373718194febcb61.tar.gz ldjam48-b66eb089dbce08f4d38df39f373718194febcb61.tar.bz2 ldjam48-b66eb089dbce08f4d38df39f373718194febcb61.zip |
[sparta] fix pause
Diffstat (limited to 'scenes')
-rw-r--r-- | scenes/PauseSprite.gd | 6 | ||||
-rw-r--r-- | scenes/levels/base_level.gd | 18 | ||||
-rw-r--r-- | scenes/levels/base_level.tscn | 8 | ||||
-rw-r--r-- | scenes/levels/reactiontest.gd | 21 | ||||
-rw-r--r-- | scenes/levels/reactiontest.tscn | 13 | ||||
-rw-r--r-- | scenes/pause.gd | 15 | ||||
-rw-r--r-- | scenes/pause.tscn | 21 |
7 files changed, 78 insertions, 24 deletions
diff --git a/scenes/PauseSprite.gd b/scenes/PauseSprite.gd new file mode 100644 index 0000000..a8ffa50 --- /dev/null +++ b/scenes/PauseSprite.gd @@ -0,0 +1,6 @@ +extends ColorRect + +func _input(event): + for c in get_parent().get_children(): + if c != self: + c._notifaction(c.NOTIFICATION_INPUT) diff --git a/scenes/levels/base_level.gd b/scenes/levels/base_level.gd index c7e68ee..df08a32 100644 --- a/scenes/levels/base_level.gd +++ b/scenes/levels/base_level.gd @@ -77,9 +77,27 @@ func _load_current_level(): _camera.path = _track func _on_MenuButton_on_click(): + _disable_input(_level_holder) _pause_menu.pause() func _on_Camera2D_done(): print("Camera movement done") _loaded_level.start() + +func _disable_input(node): + # this is barbaric + if node is Control: + node.mouse_filter = Control.MOUSE_FILTER_IGNORE + for n in node.get_children(): + _disable_input(n) + +func _enable_input(node): + if node is Control: + node.mouse_filter = Control.MOUSE_FILTER_STOP + for n in node.get_children(): + _enable_input(n) + +func _on_PauseMenu_unpause(): + _enable_input(_level_holder) + _level_holder.set_process_input(true) diff --git a/scenes/levels/base_level.tscn b/scenes/levels/base_level.tscn index 5f0a4a6..e2d57ba 100644 --- a/scenes/levels/base_level.tscn +++ b/scenes/levels/base_level.tscn @@ -15,7 +15,10 @@ script = ExtResource( 6 ) script = ExtResource( 2 ) path_color = Color( 0, 0.741176, 1, 1 ) -[node name="LevelHolder" type="Node2D" parent="."] +[node name="LevelHolder" type="Control" parent="."] +__meta__ = { +"_edit_use_anchors_": false +} [node name="Camera2D" type="Camera2D" parent="."] position = Vector2( 153.457, 427.259 ) @@ -38,6 +41,7 @@ position = Vector2( 571.642, -311.599 ) text = "Menu" [node name="PauseMenu" parent="Camera2D" instance=ExtResource( 5 )] -visible = false + [connection signal="done" from="Camera2D" to="." method="_on_Camera2D_done"] [connection signal="on_click" from="Camera2D/MenuButton" to="." method="_on_MenuButton_on_click"] +[connection signal="unpause" from="Camera2D/PauseMenu" to="." method="_on_PauseMenu_unpause"] diff --git a/scenes/levels/reactiontest.gd b/scenes/levels/reactiontest.gd index 707b97a..50f5ce2 100644 --- a/scenes/levels/reactiontest.gd +++ b/scenes/levels/reactiontest.gd @@ -1,20 +1,39 @@ extends Level onready var buttons = $ButtonHolder.get_children() - +onready var timer_label = $TimerLabel var sequence_index = 0 +var timer = 0 +var running = false + +func _total_time(): + if Settings.difficulty == Settings.Difficulty.HARD: + return 10 + return 60 + +func start(): + .start() + running = true + func _ready(): + timer = 0 for i in range(buttons.size()): buttons[i].connect("on_click", self, "_on_Any_button_click", [i]) buttons[i].text = str(i + 1) if i != 0: buttons[i].visible = false +func _process(delta): + if running: + timer += delta + timer_label.text = str(_total_time() - timer) + func _on_Any_button_click(btn_idx): if btn_idx == sequence_index: sequence_index += 1 if sequence_index == buttons.size(): + running = false finish_level() return buttons[sequence_index].visible = true diff --git a/scenes/levels/reactiontest.tscn b/scenes/levels/reactiontest.tscn index 8c98f6c..41031e3 100644 --- a/scenes/levels/reactiontest.tscn +++ b/scenes/levels/reactiontest.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://scenes/levels/reactiontest.gd" type="Script" id=1] [ext_resource path="res://components/button.tscn" type="PackedScene" id=2] +[ext_resource path="res://fonts/Flipps_Theme.tres" type="Theme" id=3] [node name="Level2" type="Node2D"] position = Vector2( 640, 320 ) @@ -53,3 +54,13 @@ fixed_width = 30 position = Vector2( 216.1, -39.8346 ) text = "9" fixed_width = 30 + +[node name="TimerLabel" type="Label" parent="."] +margin_left = -625.51 +margin_top = -296.265 +margin_right = -501.51 +margin_bottom = -215.265 +theme = ExtResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/scenes/pause.gd b/scenes/pause.gd index e65266e..0115b1a 100644 --- a/scenes/pause.gd +++ b/scenes/pause.gd @@ -1,21 +1,18 @@ -extends Node2D +extends CanvasLayer -onready var pause_menu = $"." -onready var backgroud = $Sprite +onready var pause_menu = $Node2D + +signal unpause() func pause(): + pause_mode = PAUSE_MODE_PROCESS # to be save pause_menu.visible = true - pause_menu.pause_mode = PAUSE_MODE_PROCESS # to be save get_tree().paused = true - -func _ready(): - backgroud.modulate.a = 0.5 - - func _on_Resume_on_click(): pause_menu.visible = false get_tree().paused = false + emit_signal("unpause") func _on_Main_Menu_on_click(): diff --git a/scenes/pause.tscn b/scenes/pause.tscn index 5be50dd..c494db9 100644 --- a/scenes/pause.tscn +++ b/scenes/pause.tscn @@ -1,33 +1,32 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://components/button.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/pause.gd" type="Script" id=2] -[ext_resource path="res://textures/backgrounds/background_black.png" type="Texture" id=3] [ext_resource path="res://fonts/Flipps_Theme.tres" type="Theme" id=4] -[node name="PauseMenu" type="Node2D"] +[node name="PauseMenu" type="CanvasLayer"] pause_mode = 2 script = ExtResource( 2 ) -[node name="Sprite" type="Sprite" parent="."] -modulate = Color( 1, 1, 1, 0.47451 ) -texture = ExtResource( 3 ) +[node name="Node2D" type="Node2D" parent="."] +visible = false +position = Vector2( 640, 320 ) -[node name="Resume" parent="." instance=ExtResource( 1 )] +[node name="Resume" parent="Node2D" instance=ExtResource( 1 )] pause_mode = 2 position = Vector2( 0, -50 ) z_index = 1 text = "Resume" fixed_width = 250 -[node name="Main Menu" parent="." instance=ExtResource( 1 )] +[node name="Main Menu" parent="Node2D" instance=ExtResource( 1 )] pause_mode = 2 position = Vector2( 0, 50 ) z_index = 1 text = "Main Menu" fixed_width = 250 -[node name="Label" type="Label" parent="."] +[node name="Label" type="Label" parent="Node2D"] margin_left = -140.0 margin_top = -254.0 margin_right = 143.0 @@ -40,5 +39,5 @@ __meta__ = { "_edit_use_anchors_": false } -[connection signal="on_click" from="Resume" to="." method="_on_Resume_on_click"] -[connection signal="on_click" from="Main Menu" to="." method="_on_Main_Menu_on_click"] +[connection signal="on_click" from="Node2D/Resume" to="." method="_on_Resume_on_click"] +[connection signal="on_click" from="Node2D/Main Menu" to="." method="_on_Main_Menu_on_click"] |