sync on : sync rate 80
randomize timer()
 
#constant grav = 0.4
 
type T
    x# as float
    y# as float
    sx# as float
    sy# as float
    fade# as float
    col as integer
endtype
dim S(0) as T
 
`Media
box 0, 0, 4, 4, 0, 0, rgb(255, 255, 255), 0
box 0, 4, 4, 8, 0, 0, 0, rgb(255, 255, 255) 
box 4, 4, 8, 8, 0, rgb(255, 255, 255), 0, 0
box 4, 0, 8, 4, rgb(255, 255, 255), 0, 0, 0
get image 1, 0, 0, 8, 8, 1
 
`Start timer
t# = timer()
sp# = 20
 
do
 
    cls
 
    `Start particles
    if timer() - t# => sp#
 
        `reset timer
        t# = timer()
 
        `Makle a particle
        array insert at bottom S()
        b = array count(S())
 
        S(b).x# = mousex()
        S(b).y# = mousey()
        S(b).sx# = -5.0 + (rnd(1000)*0.01)
        S(b).sy# = -rnd(500)*0.01
        S(b).fade# = 255.0
        S(b).col = rgb(rnd(255), rnd(255), rnd(255))
 
    endif
 
    `Handle all particles
    if array count(S()) > 0
        for a = array count(S()) to 1 step -1
            HandleParticle(a)
        next a
        CleanUp()
    endif
 
    `Faster or slower particles
    sp# = 20
    if mouseclick() = 1 then sp# = 1
    if mouseclick() = 2 then sp# = 40
 
    sync
loop
 
function HandleParticle(a)
 
    `Update position
    inc S(a).sy#, grav
    inc S(a).x#, S(a).sx#
    inc S(a).y#, S(a).sy#
 
    `Handle fading
    dec S(a).fade#, 5
 
    `Draw particle
    sprite a, S(a).x#, S(a).y#, 1
    set sprite diffuse a, rgbr(S(a).col), rgbg(S(a).col), rgbb(S(a).col)
    set sprite alpha a, S(a).fade#
 
    `Delete particle
    if S(a).fade# <= 0
        delete sprite a
        array delete element S(), a
    endif
 
endfunction
 
function CleanUp()
    for i = array count(S()) + 1 to 7500
        if sprite exist(i) > 0 then delete sprite i
    next i
endfunction