It's in it's beginning at the moment but I've got the basic to work and it's pretty fast so far. The demo shows two type of particles, one that trails a bullet and the other type used for smoke. The initialisation creates simple images so far but when it's finished the particles will be able to be animated and have more movement available. Any ideas welcome to improving on this.
Here's the particle code: download attached for a demo (uses sparky's but the exe will run)
type emitter
xpos as float
ypos as float
zpos as float
xrot as float
yrot as float
zrot as float
life as integer
emit as integer
rate as integer
rate_reset as integer
endtype
` =========================================
type particle
obj as integer
life as integer
emit as integer ` emitter type (0=still, 1=move up)
endtype
` =========================================
type img_list
img as integer ` start image in global list
count as integer ` numbers of images in the anim range
endtype
` =========================================
type img_one
img as integer
reserved1 as integer
endtype
` =========================================
function WLP_ADD_EMITTER(obj as integer, emit as integer)
if ( object exist(obj) )
array insert at bottom emitters()
emitters().xpos=object position x(obj)
emitters().ypos=object position y(obj)
emitters().zpos=object position z(obj)
emitters().xrot=object angle x(obj)
emitters().yrot=object angle y(obj)
emitters().zrot=object angle z(obj)
emitters().emit=emit
select emit
case 0
emitters().life=1
emitters().rate=1
endcase
case 1
emitters().life=30
emitters().rate=1
endcase
case default
emitters().life=10
emitters().rate=1
endcase
endselect
emitters().rate_reset=emitters().rate
endif
endfunction
` =========================================
function WLP_PROC_EMITTERS()
c as integer
c = array count( emitters() )
while ( c >= 0 )
if emitters(c).rate=0
emitters(c).rate=emitters(c).rate_reset
WLP_ADD_PARTICLE(c)
else
dec emitters(c).rate
endif
if ( emitters(c).life=0 )
array delete element emitters(),c
else
dec emitters(c).life
endif
dec c
endwhile
endfunction
` =========================================
` element num in emitters() array
function WLP_ADD_PARTICLE(elem as integer)
obj as integer
c as integer
r as float
select emitters(elem).emit
case 0
` add a circle particle as a basic test
array insert at bottom particles()
obj=WLP_FREE_OBJECT()
particles().obj=obj
make object plane obj,5,5
texture object obj,WLP_IMAGES(image_lists(0).img).img
set object to camera orientation obj
position object obj,emitters(elem).xpos,emitters(elem).ypos,emitters(elem).zpos
set object transparency obj,1
`yrotate object obj,object angle Y(obj+180)
particles().life=50
particles().emit=emitters(elem).emit
endcase
case 1
` add a smoke particle as another basic test
array insert at bottom particles()
obj=WLP_FREE_OBJECT()
particles().obj=obj
make object plane obj,5,5
texture object obj,WLP_IMAGES(image_lists(1).img).img
set object to camera orientation obj
r=emitters(elem).life/3
c=rnd(360)
`position object obj,emitters(elem).xpos,emitters(elem).ypos,emitters(elem).zpos
position object obj,emitters(elem).xpos+sin(c)*r,emitters(elem).ypos,emitters(elem).zpos+cos(c)*r
set object transparency obj,1
`ghost object on obj
particles().life=50
particles().emit=emitters(elem).emit
endcase
endselect
endfunction
` =========================================
function WLP_PROC_PARTICLES()
c as integer
c=array count( particles() )
while ( c>=0 )
select particles(c).emit
case 0
if ( particles(c).life = 0 )
delete object particles(c).obj
array delete element particles(),c
else
dec particles(c).life
`if particles(c).life<15
` ghost object on particles(c).obj
`endif
set alpha mapping on particles(c).obj,particles(c).life*2
endif
endcase
case 1
if ( particles(c).life = 0 )
delete object particles(c).obj
array delete element particles(),c
else
dec particles(c).life
move object up particles(c).obj,0.3
set alpha mapping on particles(c).obj,particles(c).life*2
endif
endcase
endselect
dec c
endwhile
endfunction
` =========================================
function WLP_DO_PARTICLES()
WLP_PROC_EMITTERS()
WLP_PROC_PARTICLES()
endfunction
` =========================================
function WLP_INIT_PARTICLES()
bm as integer
im as integer
c as integer
r as integer
` setup global defines
global dim emitters() as emitter
global dim particles() as particle
global dim image_lists() as img_list
global dim WLP_IMAGES() as img_one
` First particle type
` Just a circle
bm=WLP_FREE_BITMAP()
create bitmap bm,32,32
ink 0xffff00,0xffff00
circle 16,16,14
ink 0x555500,0x555500
circle 16,16,15
circle 16,16,13
dot 16,16
im=WLP_FREE_IMAGE()
get image im,0,0,31,31,0
delete bitmap bm
WLP_ADD_IMAGE(im)
WLP_ADD_IMAGE_LIST(1)
` Second particle type
` Try and make a cheap explosion
bm=WLP_FREE_BITMAP()
create bitmap bm,32,32
for c=15 to 0 step -1
r=c*16
ink rgb(r,r,r),rgb(r,0,0)
circle 16,16,c
next c
im=WLP_FREE_IMAGE()
get image im,0,0,31,31,0
delete bitmap bm
WLP_ADD_IMAGE(im)
WLP_ADD_IMAGE_LIST(1)
endfunction
` =========================================
function WLP_FREE_IMAGE()
c as integer
c=1
while ( image exist(c) )
inc c
endwhile
endfunction c
` =========================================
function WLP_FREE_BITMAP()
c as integer
c=1
while ( bitmap exist(c) )
inc c
endwhile
endfunction c
` =========================================
function WLP_ADD_IMAGE(im as integer)
array insert at bottom WLP_IMAGES()
WLP_IMAGES().img=im
endfunction
` =========================================
function WLP_ADD_IMAGE_LIST(num as integer)
c as integer
c=array count( WLP_IMAGES() )
array insert at bottom image_lists()
image_lists().count=num
image_lists().img=(c-num+1)
endfunction
` =========================================
function WLP_FREE_OBJECT()
c as integer
c=1
while ( object exist(c) )
inc c
endwhile
endfunction c
Hope it helps anyone out!
Warning! May contain Nuts!