-
Notifications
You must be signed in to change notification settings - Fork 0
/
door.gd
48 lines (36 loc) · 1019 Bytes
/
door.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
extends Area2D
var dir
var locked
var active
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
self.visible = false
var sprite = self.get_node("Sprite2D")
sprite.texture = load("res://assets/door_locked.png")
locked = true
active = false
add_to_group("Door")
body_entered.connect(on_Door_body_entered)
# Set the direction of the door
match name:
"DoorRight":
dir = 0 # Right
"DoorUp":
dir = 1 # Up
"DoorLeft":
dir = 2 # Left
"DoorDown":
dir = 3 # Down
_:
dir = -1 # Invalid direction
# Wait a moment, so player can move and not trigger the door when entering
await get_tree().create_timer(0.1).timeout
active = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func on_Door_body_entered(body) -> void:
if active && !locked && body.is_in_group("Player"):
active = false
var parentNode = get_parent().get_parent()
parentNode.nextRoom(dir)