-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspawner.gd
102 lines (68 loc) · 2.28 KB
/
spawner.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
extends Node2D
var SQUARE_TSCN = preload("res://square.tscn")
export var queue_color:PoolColorArray = PoolColorArray() setget set_queue_color
export var tick_color:PoolIntArray = PoolIntArray()
export var next_bullet = 0
export var MESH_SIZE = 7
export var SEGMENT_SIZE = 150
export var default_speed = 3
export var tick_offset = 0
var COMPLETED = "completed"
var emit_poligon
var y_pos
# Called when the node enters the scene tree for the first time.
func _ready():
y_pos = -(position.y + 75)/150
Time.connect("tick", self, "on_tick")
emit_poligon = $emit_polygon
pass
func on_tick(tick):
if !queue_color.size():
return
if tick - tick_offset == tick_color[next_bullet]:
start_next_bullet()
next_bullet = next_bullet + 1 if next_bullet < tick_color.size() - 1 else 0
tick_offset = tick
func set_queue_color(color_arr:PoolColorArray):
queue_color = color_arr
func start_next_bullet(speed = default_speed):
var a:Node2D = SQUARE_TSCN.instance()
a.start_tick = Time.tick
a.y_pos = y_pos
self.add_child(a)
a.add_to_group("bullets")
if queue_color:
a.color = queue_color[next_bullet]
var tween_speed = (MESH_SIZE + 5) / speed
if position.x > 0:
emit_color_bulet(speed, a.color)
a.direction = Vector2(-1, 0)
a.position.x += SEGMENT_SIZE * 0.5 + SEGMENT_SIZE * 3
a.start_pos = Vector2(3.5+3.0, y_pos)
a.tween = tw.ip(a, "position:x", a.position.x, a.position.x - (MESH_SIZE + 5) * SEGMENT_SIZE, tween_speed)
yield(a.tween, "tween_completed")
elif position.x < 0:
emit_color_bulet(speed, a.color)
a.direction = Vector2(1, 0)
a.position.x -= SEGMENT_SIZE * 0.5 + SEGMENT_SIZE * 3
a.start_pos = Vector2(-3.5-3.0, y_pos)
a.tween = tw.ip(a, "position:x", a.position.x, a.position.x + (MESH_SIZE + 5) * SEGMENT_SIZE, tween_speed)
yield(a.tween, "tween_completed")
if a.active:
a.queue_free()
func get_active_bullets():
var tmp = get_tree().get_nodes_in_group("bullets")
var res = []
for i in tmp:
if i.active:
res.push_back(i)
return(res)
func emit_color_bulet(speed, color):
emit_poligon.color = color
emit_poligon.color.a = 0.3
yield(Time.wait(0.7 / speed), COMPLETED)
emit_poligon.color.a = 0
yield(Time.wait(0.5 / speed), COMPLETED)
emit_poligon.color.a = 0.6
yield(Time.wait(0.7 / speed), COMPLETED)
emit_poligon.color = ("00000000")