From d42b370cdf90d4dabed8e8f0d2f542920a40d7cd Mon Sep 17 00:00:00 2001 From: Antonio Dell'Annunziata Date: Sat, 8 Mar 2025 07:18:06 +0100 Subject: [PATCH] Fix scalpel cut start --- main.tscn | 20 +++++++++++--------- operation/cut_sequence_point.gd | 28 ++++++++++++++++++++++------ operation/cut_sequence_point.tscn | 1 + operation/prototype_dark_cut.tscn | 2 ++ operation/test_scalpel.gd | 3 --- project.godot | 1 + selectable.tscn | 2 ++ 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/main.tscn b/main.tscn index f9a054d..909cd48 100644 --- a/main.tscn +++ b/main.tscn @@ -131,6 +131,8 @@ position = Vector2(242, 258) texture = SubResource("GradientTexture2D_ty4ro") [node name="Selectable" parent="Room/Bob" instance=ExtResource("3_g5hfc")] +collision_layer = 256 +collision_mask = 256 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Room/Bob/Selectable"] polygon = PackedVector2Array(-50, 100, -50, -100, 50, -100, 50, 100) @@ -203,7 +205,7 @@ collision_mask = 8 shape = SubResource("CircleShape2D_8w656") debug_color = Color(0.879882, 0.304191, 0.394852, 0.42) -[node name="TestScalpel" type="Sprite2D" parent="Shelves" groups=["cutter"]] +[node name="Scalpel" type="Sprite2D" parent="Shelves" groups=["cutter"]] z_index = 10 position = Vector2(-72.9391, -140.263) rotation = -2.00713 @@ -212,22 +214,22 @@ texture = ExtResource("20_4lmeg") offset = Vector2(-8.44019, 66.5461) script = ExtResource("21_0cp0l") -[node name="PickupArea" parent="Shelves/TestScalpel" instance=ExtResource("19_h8e4i")] +[node name="PickupArea" parent="Shelves/Scalpel" instance=ExtResource("19_h8e4i")] -[node name="CollisionShape2D2" type="CollisionShape2D" parent="Shelves/TestScalpel/PickupArea"] +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Shelves/Scalpel/PickupArea"] position = Vector2(-7.59496, 64.7336) shape = ExtResource("22_d2t1y") -[node name="CutArea" type="Area2D" parent="Shelves/TestScalpel"] +[node name="CutArea" type="Area2D" parent="Shelves/Scalpel"] collision_layer = 5 collision_mask = 5 -[node name="CollisionShape2D" type="CollisionShape2D" parent="Shelves/TestScalpel/CutArea"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="Shelves/Scalpel/CutArea"] position = Vector2(0.481193, 0.0901661) shape = SubResource("CircleShape2D_qmwrh") debug_color = Color(0.879882, 0.304191, 0.394852, 0.42) -[node name="CutHurtTimer" type="Timer" parent="Shelves/TestScalpel"] +[node name="CutHurtTimer" type="Timer" parent="Shelves/Scalpel"] unique_name_in_owner = true [node name="BatDropoff" type="Node2D" parent="Shelves" groups=["bat_dropoff"]] @@ -249,6 +251,6 @@ shape = SubResource("RectangleShape2D_0odxb") [connection signal="clicked" from="Room/Bob/Selectable" to="." method="_on_bob_clicked"] [connection signal="clicked" from="Room/RitualPlace/Selectable" to="." method="_on_ritual_place_clicked"] -[connection signal="area_entered" from="Shelves/TestScalpel/CutArea" to="Shelves/TestScalpel" method="_on_cut_area_area_entered"] -[connection signal="area_exited" from="Shelves/TestScalpel/CutArea" to="Shelves/TestScalpel" method="_on_cut_area_area_exited"] -[connection signal="timeout" from="Shelves/TestScalpel/CutHurtTimer" to="Shelves/TestScalpel" method="_on_cut_hurt_timer_timeout"] +[connection signal="area_entered" from="Shelves/Scalpel/CutArea" to="Shelves/Scalpel" method="_on_cut_area_area_entered"] +[connection signal="area_exited" from="Shelves/Scalpel/CutArea" to="Shelves/Scalpel" method="_on_cut_area_area_exited"] +[connection signal="timeout" from="Shelves/Scalpel/CutHurtTimer" to="Shelves/Scalpel" method="_on_cut_hurt_timer_timeout"] diff --git a/operation/cut_sequence_point.gd b/operation/cut_sequence_point.gd index f86627f..cdf3df4 100644 --- a/operation/cut_sequence_point.gd +++ b/operation/cut_sequence_point.gd @@ -4,12 +4,7 @@ extends Sprite2D signal point_cut var scalpel: Scalpel -func _ready(): - scalpel = get_tree().get_first_node_in_group("cutter") - -func _on_area_2d_area_entered(area): - if area != scalpel.cut_area or not scalpel.is_cutting: return - point_cut.emit() +var is_scalpel_positioned_correctly = false func confirm_cut(): visible = false @@ -18,3 +13,24 @@ func confirm_cut(): func reset_cut(): visible = true $Area2D.set_deferred("monitoring", true) + + +func _ready(): + scalpel = get_tree().get_first_node_in_group("cutter") + scalpel.cut_started.connect(_on_scalpel_cut_started) + +func _on_scalpel_cut_started(): + _register_cut() + +func _on_area_2d_area_entered(area): + if area == scalpel.cut_area: + is_scalpel_positioned_correctly = true + _register_cut() + +func _on_area_2d_area_exited(area): + is_scalpel_positioned_correctly = false + +func _register_cut(): + if is_scalpel_positioned_correctly and scalpel.is_cutting: + point_cut.emit() + diff --git a/operation/cut_sequence_point.tscn b/operation/cut_sequence_point.tscn index 393970e..fc7828a 100644 --- a/operation/cut_sequence_point.tscn +++ b/operation/cut_sequence_point.tscn @@ -18,3 +18,4 @@ position = Vector2(0, 2) shape = SubResource("CircleShape2D_e2fuh") [connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"] +[connection signal="area_exited" from="Area2D" to="." method="_on_area_2d_area_exited"] diff --git a/operation/prototype_dark_cut.tscn b/operation/prototype_dark_cut.tscn index fb1df2b..d67f4b5 100644 --- a/operation/prototype_dark_cut.tscn +++ b/operation/prototype_dark_cut.tscn @@ -82,6 +82,8 @@ position = Vector2(620, 399) texture = ExtResource("2_atjyl") [node name="Area2D" type="Area2D" parent="TestBody1"] +collision_layer = 4 +collision_mask = 4 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="TestBody1/Area2D"] polygon = PackedVector2Array(0, -250, -39.2, -250, -45.6, -246, -48.9, -246, -54.9, -239, -56.2, -239, -61.1, -230, -62.6, -230, -67.5, -210, -69, -210, -69, -181.7, -65, -168, -65, -163.3, -49, -143, -47, -128.8, -47, -124.8, -63.3, -122, -67.3, -122, -102.9, -109.8, -113.5, -116, -124.4, -116, -148.3, -106, -150, -106, -150, 49.2, -146, 67.4, -146, 71.4, -138, 93.4, -138, 99.7, -132, 106.7, -132, 109, -115.2, 109, -108.2, 102, -106.5, 102, -101.5, 86, -100, 86, -99, 35, -99, 16.8, -96.5, 26, -96, 93, -100, 140.9, -100, 163.1, -95.7, 192, -94.9, 192, -91, 246.1, -91, 250, 61, 250, 61, 236.5, 58, 230.5, 58, 217.1, 68, 38.1, 68, 64.3, 74, 82.3, 74, 85, 82, 91, 82, 92.8, 93, 93.8, 93, 95, 109.8, 95, 117.7, 88, 119.8, 88, 128.8, 9, 129.9, 9, 131.9, -42, 133.1, -42, 132, -84, 132, -90.7, 121, -103.8, 121, -105.6, 113, -107.6, 113, -109.2, 90.1, -107.1, 87, -112.5, 87, -114.9, 75, -125, 75, -127.2, 44.8, -124, 31.2, -124, 33, -144.9, 33, -151.3, 48.9, -169, 50.4, -169, 54.4, -179, 56, -179, 56, -200.6, 43, -219.7, 43, -222, 30, -232, 30, -233.2, 0, -248.3) diff --git a/operation/test_scalpel.gd b/operation/test_scalpel.gd index a87a10f..293cb5b 100644 --- a/operation/test_scalpel.gd +++ b/operation/test_scalpel.gd @@ -32,7 +32,6 @@ func _on_cut_area_area_exited(area): func start_cutting(): if is_cutting: return - print("Start cut") _scalpel_degrees_default = rotation_degrees rotation_degrees = SCALPEL_ROTATION_CUTTING _on_cut_hurt_timer_timeout() @@ -42,7 +41,6 @@ func start_cutting(): func stop_cutting(): if not is_cutting: return - print("Stop cut") rotation_degrees = _scalpel_degrees_default %CutHurtTimer.stop() is_cutting = false @@ -53,4 +51,3 @@ func _on_cut_hurt_timer_timeout(): var patience_bar = get_tree().get_first_node_in_group("patience_bar") as ProgressBar feedback_canvas_modulate.show_hurt_feedback() patience_bar.value = clampi(patience_bar.value - 5, 0, 100) - print("Splatter") diff --git a/project.godot b/project.godot index 2185474..35717dc 100644 --- a/project.godot +++ b/project.godot @@ -33,6 +33,7 @@ patience_bar="" 2d_physics/layer_2="Pickup" 2d_physics/layer_3="Body" 2d_physics/layer_4="Pliers" +2d_physics/layer_9="Selectable" [rendering] diff --git a/selectable.tscn b/selectable.tscn index dc284da..e322948 100644 --- a/selectable.tscn +++ b/selectable.tscn @@ -3,6 +3,8 @@ [ext_resource type="Script" uid="uid://bb3faymx4pbwb" path="res://selectable.gd" id="1_ayyf7"] [node name="Selectable" type="Area2D"] +collision_layer = 256 +collision_mask = 256 script = ExtResource("1_ayyf7") [connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]