How to use
All value in the make_particle are from 0 to 1 and use either
axis([number], [velocity], [acceleration], [inertia]): progressing value
or
{y, length}: reads a set of values over time in sprite data
make_particle(X, Y, Color, Angle of rotation, lifetime)
you can also use it in conjunction with
make_emitter(function, time, [every x frames])
Thank you
Id really like to hear your feedback on it !
The code
-- Axis are from 0 to 1 -- Axis(x, y, c, r) - axis variable -- {,} - axis texture [1]: texture y position [2]: texture length function make_particle(_x, _y, _c, _r, _maxl) p = { x=_x, y=_y, c=_c, r=_r, l=0, maxl=_maxl } add(particles, p) return p end function axis(_n, _v, _a, _i) return { n=_n or 0, v=_v or 0, a=_a or 0, i=_i or 1 } end function update_particle(p) -- Update all axis local _l = p.l / p.maxl _r = get_axis(p.r, _l) update_axis(p.x, cos(_r), -p.y.v * sin(_r)) update_axis(p.y, cos(_r), p.x.v * sin(_r)) update_axis(p.c) update_axis(p.r) if(p.l >= p.maxl) del(particles, p) p.l += 1 end function draw_particle(p) local _l = p.l / p.maxl pset(flr(get_axis(p.x, _l) * 127 + 0.5), flr(get_axis(p.y, _l) * 127 + 0.5), flr(get_axis(p.c, _l) * 15 + 0.5)) end function make_emitter(_f, _l, _r) add(emitters, {f=_f, l=_l, r=_r or 1}) end function update_emitter(e) if(e.l % e.r == 0) e.f() e.l -= 1 if(e.l<=0) del(emitters, e) end function update_axis(a, m, o) if not is_texture_axis(a) then a.v += a.a -- Add acceleration a.n += a.v * (m or 1) + (o or 0) -- Add velocity a.v *= a.i -- Modify by inertia end end function get_axis(a, l) if is_texture_axis(a) then return sget(flr(l * (a[2]-0.001)), a[1]) / 15 -- Get value at addr else return a.n end end function is_texture_axis(a) return a.n == nil end |
[Please log in to post a comment]