Skip to content

Commit

Permalink
Doors dont close when objects are inside (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
MecHR17 authored May 21, 2024
1 parent 11de3e9 commit 659fcbd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion assets/objects/door.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://dbpe3nn7oukb0"]
[gd_scene load_steps=7 format=3 uid="uid://dbpe3nn7oukb0"]

[ext_resource type="Texture2D" uid="uid://ctb3lbdbdrhql" path="res://textures/objects/door.png" id="1_er06o"]
[ext_resource type="Script" path="res://assets/scripts/door.gd" id="1_ok0kj"]
Expand Down Expand Up @@ -26,7 +26,12 @@ animations = [{
"speed": 5.0
}]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_vsbhg"]
size = Vector2(32, 32)

[node name="Door" type="StaticBody2D" groups=["strong"]]
collision_layer = 16
collision_mask = 0
script = ExtResource("1_ok0kj")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
Expand All @@ -36,3 +41,11 @@ shape = SubResource("RectangleShape2D_r8ewl")
sprite_frames = SubResource("SpriteFrames_1atcu")
animation = &"open"
autoplay = "default"

[node name="Area2D" type="Area2D" parent="."]
collision_layer = 0

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_vsbhg")

[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"]
7 changes: 6 additions & 1 deletion assets/scripts/door.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends StaticBody2D

@onready var area: Area2D = $Area2D

var tmp = []

func open():
Expand All @@ -11,9 +13,12 @@ func close():
fln()

func fln():
if len(tmp) == 0:
if len(tmp) == 0 and len(area.get_overlapping_bodies()) == 0:
$CollisionShape2D.set_deferred("disabled", false);
$AnimatedSprite2D.animation = "default";
else:
$CollisionShape2D.set_deferred("disabled", true);
$AnimatedSprite2D.animation = "open";

func _on_area_2d_body_exited(body):
fln()
2 changes: 1 addition & 1 deletion level_sets/Asrn/cooking/BoxCarry.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ position = Vector2(112, 400)
position = Vector2(568, 112)

[node name="Player" parent="." instance=ExtResource("4_agypc")]
position = Vector2(48, 384)
position = Vector2(384, 352)
skill = 1

[node name="Ladders" type="Node2D" parent="."]
Expand Down

0 comments on commit 659fcbd

Please sign in to comment.