-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparticle_ai.lua
62 lines (51 loc) · 1.47 KB
/
particle_ai.lua
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
local ai = {}
ai.load = {}
ai.load.default = function(i, v) -- "basic"
v.angle = math.atan2(v.a.y, v.a.x)
end
ai.load.spark = function(i, v) -- "spark"
v.angle = math.atan2(v.a.y, v.a.x)+math.random(-math.pi*33, math.pi*33)/100
local mag = math.sqrt(vector.mag_sq(v.d))
v.d.x = mag * math.cos(v.angle)
v.d.y = mag * math.sin(v.angle)
end
ai.load.explosion = function(i, v) -- "explosion"
v.angle = math.atan2(v.a.y, v.a.x)
v.info.t = math.random(0, 20)/100
end
ai.load.energy = function(i, v) -- "energy"
v.angle = math.atan2(v.a.y, v.a.x)
v.info.o = 12
end
ai.update = {}
ai.update.default = function(i, v, dt) -- "basic"
v.p = vector.sum(v.p, vector.scale(dt * 12, v.d))
v.frame = v.frame + dt * particle_info[v.type].speed
if v.frame >= #particlequad[particle_info[v.type].img]+1 then
particles[i] = nil
end
end
ai.update.explosion = function(i, v, dt) -- "explosion"
if v.info.t <= 0 then
v.frame = v.frame + dt * particle_info[v.type].speed
if v.frame >= #particlequad[particle_info[v.type].img]+1 then
particles[i] = nil
end
else
v.info.t = v.info.t - dt
if v.info.t <= 0 then
v.frame = 1
else
v.frame = #particlequad[particle_info[v.type].img]
end
end
end
ai.update.energy = function(i, v, dt) -- "energy"
v.p = vector.sum(v.p, vector.scale(dt * 60, v.d))
v.p = vector.sub(v.p, vector.scale(dt * 24, v.a))
v.info.o = v.info.o - dt * 24
if v.info.o < 0 then
particles[i] = nil
end
end
return ai