-- title: simple particle system -- author: pixelbath -- desc: basic particle system, first used in Alter Ego by Kyuchumimo -- script: lua t=0 x=96 y=24 particles = {} particletype = 'stars' local starcolors = { 1, 2, 13, 15} -- numparticles = number of particles to show -- particletype = rain|snow|stars function particleinit(numparticles, type) -- initialize particles = {} particletype = type for i = 0, numparticles do table.insert(particles, { x = math.random() * 240, y = math.random() * 136, lastx = 0, lasty = 0, color = 2, t = 0, vel = 0, }) end if particletype == 'stars' then for i = 1, #particles do particles[i].twinkle = math.random() > 0.49 -- randomly pick true/false particles[i].color = starcolors[math.random(#starcolors)] end end if particletype == 'rain' then for i = 1, #particles do particles[i].vel = math.random(3) + 1 if particles[i].vel > 2.5 then particles[i].color = 8 end end end if particletype == 'snow' then for i = 1, #particles do particles[i].color = 15 particles[i].vel = math.random() + 0.2 end end end function particleupdate() if particletype == 'stars' then for i = 1,#particles do local p = particles[i] if not p.twinkle then goto continueTwinkle end ::continueTwinkle:: if t % 15 == 0 and math.random() > 0.1 then p.color = starcolors[math.random(#starcolors)] end end end if particletype == 'rain' then for i = 1,#particles do local p = particles[i] if p.lasty and p.lasty > 136 then p.y = 0 p.lasty = 0 p.x = math.random() * 240 end p.lasty = p.y p.lastx = p.x p.x = p.x - p.vel / 5 p.y = p.y + p.vel * 1.5 end end if particletype == 'snow' then for i = 1,#particles do local p = particles[i] if p.y and p.y > 136 then p.y = 0 p.lasty = 0 p.x = math.random() * 240 end p.x = p.x - (math.random() - 0.4) p.y = p.y + p.vel end end end function particledraw() if (particletype == 'rain') then for i = 1,#particles do local p = particles[i] line(p.x, p.y, p.lastx, p.lasty, p.color) end return end for i = 1,#particles do local p = particles[i] pix(p.x, p.y, p.color) end end -- init here for title screen particleinit(150, 'snow') function TIC() if btn(0) then y=y-1 end if btn(1) then y=y+1 end if btn(2) then x=x-1 end if btn(3) then x=x+1 end cls(13) spr(1+t%60//30*2,x,y,14,3,0,0,2,2) print("HELLO WORLD!",84,84) particleupdate() particledraw() t=t+1 end -- -- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc -- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c -- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc -- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c -- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec -- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee -- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec -- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee -- -- -- 000:00000000ffffffff00000000ffffffff -- 001:0123456789abcdeffedcba9876543210 -- 002:0123456789abcdef0123456789abcdef -- -- -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 -- -- -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57 --