New source uploaded in the first post.
I found a temp work around for the masking on the particles. I added a new layer to the png image which was black.
Animated particles now works with a simple function call to add an animation WLP_LOAD_ANIM(file$,width,height). This will load a bitmap in and add the images to the animation list. Once finished it will delete the bitmap.
The new particle code: (I will update when I figure alpha channel masking)
type emitter
xpos as float
ypos as float
zpos as float
xrot as float
yrot as float
zrot as float
life as float
emit as integer
rate as float
rate_reset as float
endtype
` =========================================
type particle
obj as integer
life as float
emit as integer ` emitter type (0=still, 1=move up)
img as integer
count as integer ` number of images
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 2
emitters().life=30
emitters().rate=1
endcase
case 3
emitters().life=1
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
emitters(c).rate=emitters(c).rate-WLT_F
endif
if ( emitters(c).life<=0 )
array delete element emitters(),c
else
emitters(c).life=emitters(c).life-WLT_F
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,15,15
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
`xrotate object obj,object angle x(obj)+180
set object transparency obj,1
set object specular obj,0xffffff
set object specular power obj,1
`ghost object on obj
particles().life=100
particles().emit=emitters(elem).emit
endcase
case 2
` add explosion particle for animation
array insert at bottom particles()
obj=WLP_FREE_OBJECT() : particles().obj=obj
make object plane obj,15,15 : set object to camera orientation obj
particles().img=WLP_IMAGES( image_lists(2).img).img : texture object obj,particles().img
`set object transparency obj,1 : set alpha mapping on obj,100
set object obj,1,1,1
position object obj,emitters(elem).xpos+rnd(50)-25,emitters(elem).ypos+rnd(50)-25,emitters(elem).zpos+rnd(50)-25
particles().life=5 : particles().emit=emitters(elem).emit : particles().count=0
endcase
case 3
` add explosion particle for animation
array insert at bottom particles()
obj=WLP_FREE_OBJECT() : particles().obj=obj
make object plane obj,15,15 : set object to camera orientation obj
particles().img=WLP_IMAGES( image_lists(3).img).img : texture object obj,particles().img
set object obj,1,1,1
position object obj,emitters(elem).xpos,emitters(elem).ypos,emitters(elem).zpos
particles().life=1 : particles().emit=emitters(elem).emit : particles().count=0
endcase
endselect
endfunction
` =========================================
function WLP_PROC_PARTICLES()
c as integer
c=array count( particles() )
while ( c>=0 )
select particles(c).emit
case 0
set object to camera orientation particles(c).obj
if ( particles(c).life <= 0 )
delete object particles(c).obj
array delete element particles(),c
else
move object up particles(c).obj,0.1*WLT_F
set alpha mapping on particles(c).obj,particles(c).life*2
particles(c).life=particles(c).life-WLT_F
endif
endcase
case 1
set object to camera orientation particles(c).obj
if ( particles(c).life <= 0 )
delete object particles(c).obj
array delete element particles(),c
else
` it actually moves up but I rotated the particle to make it shine better
move object up particles(c).obj,0.4*WLT_F
set alpha mapping on particles(c).obj,particles(c).life
particles(c).life=particles(c).life-WLT_F
endif
endcase
case 2
set object to camera orientation particles(c).obj
if ( particles(c).life <= 0 )
inc particles(c).count
if particles(c).count>=image_lists(2).count
delete object particles(c).obj
array delete element particles(),c
else
particles(c).life=10
particles(c).img=WLP_IMAGES(image_lists(2).img+particles(c).count).img
texture object particles(c).obj, particles(c).img
endif
else
move object up particles(c).obj,0.4*WLT_F
particles(c).life=particles(c).life-WLT_F
endif
endcase
case 3
set object to camera orientation particles(c).obj
if ( particles(c).life <= 0 )
inc particles(c).count
if particles(c).count>=image_lists(3).count
delete object particles(c).obj
array delete element particles(),c
else
particles(c).life=1
particles(c).img=WLP_IMAGES(image_lists(3).img+particles(c).count).img
texture object particles(c).obj, particles(c).img
endif
else
move object up particles(c).obj,0.4*WLT_F
particles(c).life=particles(c).life-WLT_F
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
set image colorkey 0,0,0
` 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
ink 0x000000,0x000000
box 12,0,19,31
box 0,12,31,19
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=255-c*16
ink rgb(r,r,0),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)
` Now load up an animated explosion particle effect
WLP_LOAD_ANIM("images\exp1.png",4,4)
` Load up another animated particle effect for the bullet trails
WLP_LOAD_ANIM("images\exp2b.png",3,4)
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
` =========================================
` add a single image to the image list
function WLP_ADD_IMAGE(im as integer)
array insert at bottom WLP_IMAGES()
WLP_IMAGES().img=im
endfunction
` =========================================
` this will add a list of the last images
` added to another structure for animated
` particles
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
` =========================================
` create an image list out of a pic for animated particles
function WLP_LOAD_ANIM(file$,wid as integer,hgt as integer)
bm as integer
bwid as integer
bhgt as integer
x as integer
y as integer
bm=WLP_FREE_BITMAP()
load bitmap file$,bm
if bm=0 then exitfunction
set current bitmap bm : bwid=bitmap width(bm) : bhgt=bitmap height(bm)
for y=0 to bhgt-1 step bhgt/hgt
for x=0 to bwid-1 step bwid/wid
WLP_ADD_NEW_IMAGE(x,y,bwid/wid,bhgt/hgt)
next
next
WLP_ADD_IMAGE_LIST(wid*hgt)
delete bitmap bm
endfunction
` =========================================
function WLP_ADD_NEW_IMAGE(x as integer,y as integer,w as integer,h as integer)
im as integer
im=WLP_FREE_IMAGE()
get image im,x,y,x+w-1,y+h-1,0
WLP_ADD_IMAGE(im)
endfunction
NB: I've added my MSN to my profile. This is just for programmers, developers, graphics designers, modelling, etc. I don't like to chat, I've got the missus for that. But all messages will be replied to. Thank you for your support in this project and lets keep it free...
Warning! May contain Nuts!