-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbonfire.gd
55 lines (44 loc) · 1.16 KB
/
bonfire.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
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 rest")
else:
label.set_text("Press E to light bonfire")
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()
for b in bodies:
if b.is_in_group("player"):
print("found player")
b.last_bonfire = self
if !anim_spr.is_visible():
anim_spr.show()
static_spr.hide()
light.show()
else:
activate(b)
func activate(player):
print("gave health and resetted")
# give player health and revive all enemies
player.health = 100
get_parent().get_parent().reset_enemies()
func _ready():
set_process(true)
# flicker
func _on_Timer_timeout():
var energy = randf()*0.7+0.7
light.set_energy(energy)