fililou [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=38659 Particle System <p> <table><tr><td> <a href="/bbs/?pid=65839#p"> <img src="/bbs/thumbs/pico8_pojawomawa-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=65839#p"> Particle System 1.0.1</a><br><br> by <a href="/bbs/?uid=38659"> fililou</a> <br><br><br> <a href="/bbs/?pid=65839#p"> [Click to Play]</a> </td></tr></table> </p> <h1>How to use</h1> <p>All value in the make_particle are from 0 to 1 and use either<br /> axis([number], [velocity], [acceleration], [inertia]): progressing value<br /> or<br /> {y, length}: reads a set of values over time in sprite data<br /> make_particle(X, Y, Color, Angle of rotation, lifetime)<br /> you can also use it in conjunction with<br /> make_emitter(function, time, [every x frames])</p> <h1>Thank you</h1> <p>Id really like to hear your feedback on it ! </p> <h1>The code</h1> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>-- 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 &gt;= 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&lt;=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</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=34723 https://www.lexaloffle.com/bbs/?tid=34723 Sun, 14 Jul 2019 17:39:42 UTC