fix: better mine trigger behavior

This commit is contained in:
Jakob Feldmann 2023-10-10 14:02:18 +02:00
parent 44b6cbf379
commit bbbd36d91b
2 changed files with 36 additions and 61 deletions

View File

@ -6,25 +6,37 @@ extends Node2D
# var b: String = "text"
export var is_armed = false
var trigger_zone_entered: bool = false
func _ready() -> void:
if(!is_armed):
$Area2D.remove_from_group("harmful")
if($HarmfulArea.is_in_group("harmful")):
$HarmfulArea.remove_from_group("harmful")
$Sprite/AnimationPlayer.play("unarmed")
else:
$Area2D.add_to_group("harmful")
$HarmfulArea.add_to_group("harmful")
$Sprite/AnimationPlayer.play("armed")
func _on_Area2D_area_exited(area: Area2D) -> void:
if(area.is_in_group("player")):
$Timer.start()
func _on_Timer_timeout() -> void:
is_armed = true
$Area2D.add_to_group("harmful")
$HarmfulArea.add_to_group("harmful")
$Sprite/AnimationPlayer.play("arming")
func _on_AnimationPlayer_animation_finished(anim_name: String) -> void:
if(anim_name == "arming"):
$Sprite/AnimationPlayer.play("armed")
func _on_DetectionArea_area_exited(area: Area2D) -> void:
if(area.is_in_group("player") && !$HarmfulArea.is_in_group("harmful")
&& trigger_zone_entered):
$Timer.start()
trigger_zone_entered = false
func _on_HarmfulArea_area_entered(area: Area2D) -> void:
if(area.is_in_group("player")):
trigger_zone_entered = true

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://assets/obstacle object/SpikyMinePlant.png" type="Texture" id=1]
[ext_resource path="res://src/ObstacleObjects/Mine.gd" type="Script" id=2]
@ -17,18 +17,6 @@ tracks/0/keys = {
"update": 0,
"values": [ 0 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("../Area2D/CollisionShape2D:shape:radius")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 4.0 ]
}
[sub_resource type="Animation" id=8]
resource_name = "armed"
@ -46,18 +34,6 @@ tracks/0/keys = {
"update": 1,
"values": [ 22, 23, 24, 25, 26, 27, 28, 29 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("../Area2D/CollisionShape2D:shape:radius")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 7.0 ]
}
[sub_resource type="Animation" id=6]
resource_name = "arming"
@ -74,18 +50,6 @@ tracks/0/keys = {
"update": 1,
"values": [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("../Area2D/CollisionShape2D:shape:radius")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.00519588, 0.698901 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ 4.0, 7.0 ]
}
[sub_resource type="Animation" id=3]
resource_name = "unarmed"
@ -103,22 +67,14 @@ tracks/0/keys = {
"update": 1,
"values": [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("../Area2D/CollisionShape2D:shape:radius")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 4.0 ]
}
[sub_resource type="CircleShape2D" id=7]
[sub_resource type="CircleShape2D" id=12]
resource_local_to_scene = true
radius = 4.0
radius = 6.0
[sub_resource type="CircleShape2D" id=9]
resource_local_to_scene = true
radius = 9.0
[node name="Mine" type="Node2D"]
script = ExtResource( 2 )
@ -135,16 +91,23 @@ anims/armed = SubResource( 8 )
anims/arming = SubResource( 6 )
anims/unarmed = SubResource( 3 )
[node name="Area2D" type="Area2D" parent="."]
[node name="HarmfulArea" type="Area2D" parent="."]
collision_layer = 64
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 7 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="HarmfulArea"]
shape = SubResource( 12 )
[node name="DetectionArea" type="Area2D" parent="."]
collision_layer = 64
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea"]
shape = SubResource( 9 )
[node name="Timer" type="Timer" parent="."]
wait_time = 0.1
one_shot = true
[connection signal="animation_finished" from="Sprite/AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"]
[connection signal="area_exited" from="Area2D" to="." method="_on_Area2D_area_exited"]
[connection signal="area_entered" from="HarmfulArea" to="." method="_on_HarmfulArea_area_entered"]
[connection signal="area_exited" from="DetectionArea" to="." method="_on_DetectionArea_area_exited"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]