-
Notifications
You must be signed in to change notification settings - Fork 1
/
Candy.gd
99 lines (73 loc) · 1.6 KB
/
Candy.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
extends Area2D
var x
var y
var destx
var desty
var posx
var posy
var color
var special = false
var sel = false
signal selected(obj, b)
func _ready():
randomize()
color = int(rand_range(0, 6))
if rand_range(0, 1) > 0.99:
special = true
if special:
get_node("Sprite").set_animation("shine" + get_color(color))
else:
get_node("Sprite").set_animation("normal" + get_color(color))
set_process(true)
func _process(delta):
if destx == null or desty == null or (destx == x and desty == y): return
var delx = posx - get_pos().x
var dely = posy - get_pos().y
var speed = Vector2(0, 0)
if abs(delx) > 20:
speed.x = 300*(destx - x)
else:
set_pos(Vector2(posx, get_pos().y))
x = destx
if abs(dely) > 20:
speed.y = 300*(desty - y)
else:
set_pos(Vector2(get_pos().x, posy))
y = desty
set_pos(get_pos() + speed * delta)
func get_color(n):
if n == 0:
return "Blue"
elif n == 1:
return "Green"
elif n == 2:
return "Orange"
elif n == 3:
return "Pink"
elif n == 4:
return "Purple"
elif n == 5:
return "Yellow"
func _on_Candy_input_event( viewport, event, shape_idx ):
if event.type == InputEvent.SCREEN_TOUCH and event.pressed:
if sel:
desel()
emit_signal("selected", self, false)
else:
sel()
emit_signal("selected", self, true)
func desel():
sel = false
get_node("Sel").hide()
func sel():
sel = true
get_node("Sel").show()
func set_data(x, y):
self.x = x
self.y = y
set_pos(Vector2(62 + x * 75 + 75/2, 290 + y * 75 + 75/2))
func move_to(gx, gy):
destx = gx
desty = gy
posx = get_pos().x + (gx - x) * 75
posy = get_pos().y + (gy - y) * 75