-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtorch.gd
More file actions
48 lines (40 loc) · 1008 Bytes
/
Copy pathtorch.gd
File metadata and controls
48 lines (40 loc) · 1008 Bytes
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 Node2D
onready var light = get_node("Light2D")
onready var anim_spr = get_node("AnimSprite")
onready var static_spr = get_node("StaticSprite")
onready var area = get_node("InteractArea")
onready var label = get_node("HUD/CenterContainer/InteractLabel")
func _process(delta):
if anim_spr.is_visible():
label.set_text("Press E to extinguish torch")
else:
label.set_text("Press E to light torch")
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():
if !anim_spr.is_visible():
anim_spr.show()
static_spr.hide()
light.show()
else:
anim_spr.hide()
static_spr.show()
light.hide()
func _ready():
set_process(true)
# flicker
func _on_Timer_timeout():
var energy = randf()*0.55+0.55
light.set_energy(energy)