forked from coderman64/flow-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
boostParticle.gd
64 lines (43 loc) · 1.19 KB
/
boostParticle.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
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var initialVel = Vector2()
var cVel = initialVel
export(float) var boostValue = 2
var player
var boostBar
var line
var lineLength = 30
var speed = 10
var oPos
var lPos
var timer = 0
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
initialVel = Vector2(randf()-0.5,randf()-0.5)
initialVel = initialVel.normalized()*speed
player = get_node("/root/Node2D/Player")
boostBar = get_node("/root/Node2D/CanvasLayer/boostBar")
line = get_node("Line2D")
oPos = position
lPos = oPos
for i in range(lineLength):
line.points[i] = Vector2(0,0)
func _process(delta):
if timer < 1:
timer += delta
else:
timer = 1
speed += delta*10
cVel = initialVel.linear_interpolate((player.position-position).normalized()*speed,timer)
position = oPos.linear_interpolate(player.position,timer)
oPos += initialVel
for i in range(lineLength-1,0,-1):
line.points[i] = line.points[i-1]-(position-lPos)
line.points[0] = Vector2(0,0)
if timer >= 1 and position.distance_to(player.position) <= speed:
boostBar.changeBy(boostValue)
queue_free()
lPos = position