summaryrefslogtreecommitdiff
path: root/Scenes/Crystal.gd
blob: af5ece45374f122a25db916a958a40cefc05fac5 (plain)
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
extends Entity

class_name Crystal

export(bool) var is_active = false
export(Color) var active_color

onready var mesh : MeshInstance = $Mesh

func _ready():
	._ready()
	add_to_group("crystals")

func cor_activate(args : Array):
	var duration = args[0]
	var time = 0

	var material = mesh.get_active_material(0)
	var color = material.albedo_color

	while true:
		time = min(time + get_process_delta_time(), duration)
		var weight = time / duration

		material.albedo_color = color.linear_interpolate(active_color, weight)

		if time >= duration:
			break

		yield(get_tree(), "idle_frame")
	
	$AudioStreamPlayer.play()
	$AnimationPlayer.play("Activate")
	yield($AnimationPlayer,"animation_finished")
	$AnimationPlayer.play("Active")
	
	is_active = true
	Global.active_crystals += 1