-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlexusBackground.tscn
91 lines (81 loc) · 2.13 KB
/
PlexusBackground.tscn
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
[gd_scene load_steps=2 format=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Control
export var maxDots = 70
var positions = []
var sizes = []
var velocities = []
func _ready():
for i in maxDots:
spawnNew(Vector2(rand_range(-100, self.rect_size.x+100), rand_range(-100, self.rect_size.y+100)))
func _process(delta):
#Spawning
if positions.size() < maxDots:
spawnNew()
#Movement
for dot in positions:
positions[positions.find(dot)] += velocities[positions.find(dot)]
#Destroying
for dot in positions:
if dot.x < -200 || dot.y < -200 || dot.x > self.rect_size.x + 200 || dot.y > self.rect_size.y + 200:
var dotID = positions.find(dot)
positions.remove(dotID)
sizes.remove(dotID)
velocities.remove(dotID)
update()
func spawnNew(pos = null):
if pos == null:
pos = newRandPos()
var size = rand_range(5, 10)
var vel = Vector2(rand_range(-1, 1), rand_range(-1, 1))
positions.append(pos)
sizes.append(size)
velocities.append(vel)
func _draw():
for dot in positions:
var dotID = positions.find(dot)
draw_circle(positions[dotID], sizes[dotID], Color.white)
#Connecting
for dot in positions:
for otherDot in positions:
if dot.distance_to(otherDot) < 300.0:
var alpha = clamp(dot.distance_to(otherDot)/120, 0, 2)
draw_line(dot, otherDot, Color(1,1,1, alpha), 1.0, true)
func newRandPos():
#Top
var x1 = rand_range(-200, self.rect_size.x + 200)
var y1 = rand_range(-200, -100)
#Bottom
var x2 = rand_range(-200, self.rect_size.x + 200)
var y2 = rand_range(self.rect_size.y+ 100, self.rect_size.y + 200)
#Left
var x3 = rand_range(-200, -100)
var y3 = rand_range(-200, self.rect_size.y + 200)
#Right
var x4 = rand_range(self.rect_size.x + 100, self.rect_size.x + 200)
var y4 = rand_range(-200, self.rect_size.y + 200)
var pos = Vector2()
var choose = int(rand_range(1,5))
match choose:
1:
pos.x = x1
pos.y = y1
2:
pos.x = x2
pos.y = y2
3:
pos.x = x3
pos.y = y3
4:
pos.x = x4
pos.y = y4
return pos
"
[node name="PlexusBackground" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
script = SubResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}