-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticles.lua
More file actions
91 lines (71 loc) · 1.32 KB
/
particles.lua
File metadata and controls
91 lines (71 loc) · 1.32 KB
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
-- Particle System
particles={
smoke_trail={
emit="continuous",
rate=0.1,
colors={7,6,6,6,6,6,6},
radius={1.5,6},
fill={█,▒,▒,░,░,░,░},
lifetime=1.5,
}
}
function create_particle(x,y,z,key)
local params=particles[key]
local p={
x=x,y=y,z=z,
key=key,
update=update_particle,
draw=draw_particle,
timer=0
}
add(ents, p)
return p
end
function update_particle(p)
local params=particles[p.key]
p.timer+=1/fps
if p.timer>params.lifetime then
del(ents,p)
end
-- interpolate values
local r=p.timer/params.lifetime
-- fill pattern
local n=#params.fill
local i=flr(r*n)+1
p.fill=params.fill[i]
-- radius
local d=params.radius[2]-params.radius[1]
i=r*d
p.radius=params.radius[1]+i
-- color
n=#params.colors
i=flr(r*n)+1
p.color=params.colors[i]
end
function draw_particle(p)
local params=particles[p.key]
local x,y=scrn_xy(p.x,p.y,p.z)
fillp(p.fill)
circfill(x,y,p.radius,p.color)
fillp()
end
function emit(x,y,z,key)
local e={
key=key,
x=x,y=y,z=z,
update=update_emitter,
draw=noop,
timer=0
}
add(ents,e)
create_particle(e.x,e.y,e.z,e.key)
return e
end
function update_emitter(e)
local params=particles[e.key]
e.timer+=1/fps
if e.timer>=params.rate then
e.timer=params.rate-e.timer -- reset timer
create_particle(e.x,e.y,e.z,e.key)
end
end