-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoor.gd
59 lines (46 loc) · 1.31 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
extends Node2D
onready var area = get_node("InteractArea")
onready var open = get_node("Open")
onready var closed = get_node("Closed")
onready var closed_body = get_node("ClosedBody")
onready var open_body = get_node("OpenBody")
onready var label = get_node("HUD/CenterContainer/InteractLabel")
onready var open_occlud = get_node("OpenOcclud")
onready var closed_occlud = get_node("ClosedOcclud")
func _process(delta):
if player_in_range():
label.show()
else:
label.hide()
func player_in_range():
var bodies = area.get_overlapping_bodies()
for b in bodies:
if b.is_in_group("player"):
return true
return false
func try_interaction():
var bodies = area.get_overlapping_bodies()
if player_in_range():
toggle()
func toggle():
# close it
if !closed.is_visible():
closed.show()
open.hide()
closed_body.set_layer_mask(1)
closed_body.set_collision_mask(1)
open_body.set_layer_mask(2)
open_body.set_collision_mask(2)
open_occlud.set_occluder_light_mask(2)
closed_occlud.set_occluder_light_mask(1)
else:
closed.hide()
open.show()
closed_body.set_layer_mask(2)
closed_body.set_collision_mask(2)
open_body.set_layer_mask(1)
open_body.set_collision_mask(1)
open_occlud.set_occluder_light_mask(1)
closed_occlud.set_occluder_light_mask(2)
func _ready():
set_process(true)