-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tutorial.gd
81 lines (61 loc) · 1.79 KB
/
Tutorial.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
extends Node2D
var level: Node2D
var step_index:int = 0
var total_steps: int
var highlight: Material
var not_highlight: Material
var run_animation = true
var tutorial: Array
var animation_timer: SceneTreeTimer
func _ready():
level = get_parent()
highlight = CanvasItemMaterial.new()
highlight.blend_mode = BLEND_MODE_ADD
not_highlight = CanvasItemMaterial.new()
not_highlight.blend_mode = BLEND_MODE_MIX
func tutorial_complete(action):
if step_index >= len(tutorial):
return
var finish_action = tutorial[step_index][2]
if action == finish_action:
stop_animation()
step_index += 1
if step_index < len(tutorial):
var timer = get_tree().create_timer(0.5) # Wait a little while before showing the next step
timer.connect('timeout', self, 'next')
else:
finish()
func finish():
stop_animation()
$Instructions.text = "Congratulations! You've finished the tutorial."
var timer = get_tree().create_timer(5)
timer.connect('timeout', self, 'hide_tutorial')
func start():
tutorial = level.objects['tutorial']
next()
func next():
var step = tutorial[step_index]
$Instructions.text = step[0]
var node: Node
if step[1] == "last_object":
node = level.last_created_object
else:
node = get_tree().get_root().get_node(step[1])
animate(node)
func animate(node):
run_animation = true
_anim1(node)
func stop_animation():
run_animation = false
#animation_timer.disconnect("timeout", self, '_anim2')
func _anim1(node):
if run_animation:
node.material = highlight
animation_timer = get_tree().create_timer(0.2)
animation_timer.connect('timeout', self, '_anim2', [node])
func _anim2(node):
node.material = not_highlight
animation_timer = get_tree().create_timer(0.2)
animation_timer.connect('timeout', self, '_anim1', [node])
func hide_tutorial():
visible = false