Here's another good one.
`setup
sync on : sync rate 60
load dll "user32.dll",1
sw=call dll(1,"GetSystemMetrics",0)
sh=call dll(1,"GetSystemMetrics",1)
set display mode sw,sh,32
delete dll 1
hide mouse
backdrop on : color backdrop 0
`Ball data
ox#=screen width()/2 : oy#=screen height()/2
mass#=100 : radius=10
`Create Particles
setupParticles()
prt1=addParticles(0,0,0,30,30)
setParticleSize(prt1,120,-4)
colorParticles(prt1,255,0,0)
prt2=addParticles(0,0,0,30,30)
setParticleSize(prt2,120,-4)
colorParticles(prt2,0,255,0)
prt3=addParticles(0,0,0,30,30)
setParticleSize(prt3,120,-4)
colorParticles(prt3,0,0,255)
prt4=addParticles(0,0,0,30,30)
setParticleSize(prt4,120,-4)
colorParticles(prt4,255,255,0)
prt5=addParticles(0,0,0,30,30)
setParticleSize(prt5,120,-4)
pball=addParticles(0,0,0,30,30)
setParticleSize(pball,120,-4)
colorParticles(pball,0,128,250)
pfire2=addParticles(0,0,0,60,60)
setParticleSize(pfire2,240,-4)
colorParticles(pfire2,0,0,128)
pfire=addParticles(0,0,0,60,60)
setParticleSize(pfire,240,-4)
colorParticles(pfire,255,128,0)
createParticles()
`Mode
mode=1
`Main Loop
do
if mode=1
pick screen mousex(),mousey(),1000
px#=get pick vector x()+plusmin(rnd(15))
py#=get pick vector y()+plusmin(rnd(15))
pz#=get pick vector z()+plusmin(rnd(15))
else
pick screen (screen width()/2)+plusmin(rnd(screen width()/2)),screen height(),1000
px#=get pick vector x()
py#=get pick vector y()
pz#=get pick vector z()
endif
pick screen (screen width()/2)+plusmin(rnd(screen width()/2)),screen height(),1000
fx#=get pick vector x()
fy#=get pick vector y()
fz#=get pick vector z()
pick screen (screen width()/2)+plusmin(rnd(screen width()/2)),screen height(),1000
f2x#=get pick vector x()
f2y#=get pick vector y()
f2z#=get pick vector z()
positionParticles(prt1,px#,py#,pz#)
positionParticles(prt2,px#,py#,pz#)
positionParticles(prt3,px#,py#,pz#)
positionParticles(prt4,px#,py#,pz#)
positionParticles(prt5,px#,py#,pz#)
positionParticles(pfire,fx#,fy#,fz#)
positionParticles(pfire2,f2x#,f2y#,f2z#)
ang#=wrapvalue(ang#+2) : grav#=6
for p=prt1 to prt4
setParticleGravity(p,sin(ang#+(p*90))*grav#,(cos(ang#+(p*90))*grav#)+(grav#*(1-mode)),0)
setParticleAlpha(p,sin(ang#)*100)
next p
setParticleGravity(prt5,0,(grav#*(1-mode)),0)
setParticleGravity(pfire,0,grav#,0)
setParticleGravity(pfire2,0,grav#,0)
dist#=sqrt((mousex()-ox#)^2+(mousey()-oy#)^2)
omang#=atanfull(mousex()-ox#,mousey()-oy#)
frc#=-((mass#*radius)/dist#)*2
frcx#=sin(omang#)*frc#
frcy#=(cos(omang#)*frc#)
accx#=frcx#/mass#
accy#=frcy#/mass#
spdx#=spdx#+accx#
spdy#=spdy#+accy#
ox#=ox#+spdx#
oy#=oy#+spdy#
spdx#=spdx#*0.98
spdy#=spdy#*0.98
if ox#<=0 then spdx#=0-spdx#
if oy#<=0 then spdy#=0-spdy#
if ox#>=screen width() then spdx#=0-spdx#
if oy#>=screen height() then spdy#=0-spdy#
pick screen ox#,oy#,1000
bx#=get pick vector x()
by#=get pick vector y()
bz#=get pick vector z()
positionParticles(pball,bx#,by#,bz#)
controlParticles()
sync
loop
function plusmin(num#)
rand=rnd(10)
if rand>5 then ret#=num#*-1 else ret#=num#
endfunction ret#
function setupParticles()
dim prtsys(0) as tprtsys
endfunction
function createParticles()
count=array count(prtsys())
cmax=0
for c=1 to count
if prtsys(c).count>cmax then cmax=prtsys(c).count
next c
dim prtdat(array count(prtsys()),cmax) as tprtdat
for c=1 to array count(prtsys())
for o=1 to prtsys(c).count
prtdat(c,o).obj=val(getToken(prtsys(c).objc,",",o))
next o
next c
endfunction count
function addParticles(x#,y#,z#,life,count)
array insert at bottom prtsys()
num=array count(prtsys())
prtsys(num).pos.x=x#+plusmin(rnd(0.2))
prtsys(num).pos.y=y#+plusmin(rnd(0.2))
prtsys(num).pos.z=z#+plusmin(rnd(0.2))
prtsys(num).life=life
prtsys(num).count=count
prtsys(num).alpha=100
for c=1 to prtsys().count
obj=zp_freeobject() : make object plain obj,20,20
set object transparency obj,3
disable object zwrite obj
ghost object on obj
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
obj$=obj$+str$(obj)+","
lifep=rnd(life)
life$=life$+str$(lifep)+","
next c
prtsys(num).objc=obj$
prtsys(num).lifep=life$
endfunction num
function setParticleSpeed(num,speed#)
prtsys(num).speed=speed#
endfunction
function setParticleSize(num,size#,sizep#)
prtsys(num).sizei=size#
prtsys(num).sizep=sizep#
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
scale object obj,size#,size#,1
next c
endfunction
function setParticleAlpha(num,alpha)
prtsys(num).alpha=alpha
endfunction
function positionParticles(num,x#,y#,z#)
prtsys(num).pos.x=x#
prtsys(num).pos.y=y#
prtsys(num).pos.z=z#
endfunction
function setParticleGravity(num,x#,y#,z#)
prtsys(num).grav.x=x#
prtsys(num).grav.y=y#
prtsys(num).grav.z=z#
endfunction
function colorParticles(num,r,g,b)
col=rgb(r,g,b)
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
color object obj,col
next c
endfunction
function controlParticles()
for num=1 to array count(prtsys())
for c=1 to prtsys(num).count
prtsys(num).lifec=prtsys(num).lifec+1
prtsys(num).lifecount=prtsys(num).life-prtsys(num).lifec
obj=prtdat(num,c).obj
angx#=angx#+((360/prtsys(num).count)*c)
angy#=angy#+((360/prtsys(num).count)*c)
sx#=object position x(obj)+(sin(angy#)*cos(angx#)*prtsys(num).speed)
sy#=object position y(obj)-(sin(angx#)*prtsys(num).speed)
sz#=object position z(obj)+(cos(angy#)*cos(angx#)*prtsys(num).speed)
sx#=sx#+prtsys(num).grav.x
sy#=sy#+prtsys(num).grav.y
sz#=sz#+prtsys(num).grav.z
size#=prtsys(num).sizei+(prtsys(num).sizep*prtsys(num).lifecount)
position object obj,sx#,sy#,sz#
scale object obj,size#,size#,1
set alpha mapping on obj,prtsys(num).alpha
if prtsys(num).lifec>prtsys(num).life
prtsys(num).lifec=prtsys(num).lifec*0
size#=prtsys(num).sizei
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
endif
next c
next num
endfunction
`Functions
function zp_freeobject()
repeat
inc i
until object exist(i)=0
endfunction i
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
endfunction token$
`UDTs
type vec3
x as float
y as float
z as float
endtype
type tprtsys
objc as string
pos as vec3
life as integer
lifec as integer
lifecount as integer
lifep as string
count as integer
speed as float
sizei as float
sizep as float
alpha as integer
grav as vec3
endtype
type tprtdat
obj as integer
endtype
[edit]
Another. Slightly less colourfull, but shows it's true purpose.
`setup
sync on : sync rate 60
load dll "user32.dll",1
sw=call dll(1,"GetSystemMetrics",0)
sh=call dll(1,"GetSystemMetrics",1)
set display mode sw,sh,32
delete dll 1
hide mouse
backdrop on : color backdrop 0
set camera range 1,0x7fffffff
setupParticles()
`Make a simple boat
make object box 1,50,20,100
make object box 2,10,100,10 : make mesh from object 1,2 : delete object 2
add limb 1,1,1 : offset limb 1,1,0,45,30
delete mesh 1
make mesh from object 1,1
delete object 1
make object 1,1,0
delete mesh 1
color object 1,rgb(128,64,0)
`make sea
make matrix 1,10000,10000,50,50
`Smoke particles
psmoke=addParticles(0,0,0,30,30)
setParticleSize(psmoke,20,20)
colorParticles(psmoke,230,200,200)
setParticleGravity(psmoke,0,5,0)
setParticleAlpha(psmoke,50)
createParticles()
`Main Loop
do
`control object
if leftkey() then yrotate object 1,wrapvalue(object angle y(1)-3)
if rightkey() then yrotate object 1,wrapvalue(object angle y(1)+3)
a#=object angle y(1)
if upkey() then move object 1,10
if downkey() then move object 1,-10
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
`camera
ca#=curveangle(a#,ca#,20.0)
cx#=x#-(sin(ca#)*600)
cy#=y#+300
cz#=z#-(cos(ca#)*600)
position camera cx#,cy#,cz# : point camera x#,y#,z#
`Particle data
prtx#=x#+(sin(a#)*30)+plusmin(rnd(10))
prty#=95
prtz#=z#+(cos(a#)*30)+plusmin(rnd(10))
positionParticles(psmoke,prtx#,prty#,prtz#)
controlParticles()
sync
loop
function plusmin(num#)
rand=rnd(10)
if rand>5 then ret#=num#*-1 else ret#=num#
endfunction ret#
function setupParticles()
dim prtsys(0) as tprtsys
endfunction
function createParticles()
count=array count(prtsys())
cmax=0
for c=1 to count
if prtsys(c).count>cmax then cmax=prtsys(c).count
next c
dim prtdat(array count(prtsys()),cmax) as tprtdat
for c=1 to array count(prtsys())
for o=1 to prtsys(c).count
prtdat(c,o).obj=val(getToken(prtsys(c).objc,",",o))
next o
next c
endfunction count
function addParticles(x#,y#,z#,life,count)
array insert at bottom prtsys()
num=array count(prtsys())
prtsys(num).pos.x=x#+plusmin(rnd(0.2))
prtsys(num).pos.y=y#+plusmin(rnd(0.2))
prtsys(num).pos.z=z#+plusmin(rnd(0.2))
prtsys(num).life=life
prtsys(num).count=count
prtsys(num).alpha=100
for c=1 to prtsys().count
obj=zp_freeobject() : make object plain obj,20,20
set object transparency obj,3
disable object zwrite obj
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
obj$=obj$+str$(obj)+","
lifep=rnd(life)
life$=life$+str$(lifep)+","
next c
prtsys(num).objc=obj$
prtsys(num).lifep=life$
endfunction num
function setParticleSpeed(num,speed#)
prtsys(num).speed=speed#
endfunction
function setParticleSize(num,size#,sizep#)
prtsys(num).sizei=size#
prtsys(num).sizep=sizep#
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
scale object obj,size#,size#,1
next c
endfunction
function setParticleAlpha(num,alpha)
prtsys(num).alpha=alpha
endfunction
function positionParticles(num,x#,y#,z#)
prtsys(num).pos.x=x#
prtsys(num).pos.y=y#
prtsys(num).pos.z=z#
endfunction
function setParticleGravity(num,x#,y#,z#)
prtsys(num).grav.x=x#
prtsys(num).grav.y=y#
prtsys(num).grav.z=z#
endfunction
function colorParticles(num,r,g,b)
col=rgb(r,g,b)
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
color object obj,col
next c
endfunction
function controlParticles()
for num=1 to array count(prtsys())
for c=1 to prtsys(num).count
prtsys(num).lifec=prtsys(num).lifec+1
prtsys(num).lifecount=prtsys(num).life-prtsys(num).lifec
obj=prtdat(num,c).obj
angx#=angx#+((360/prtsys(num).count)*c)
angy#=angy#+((360/prtsys(num).count)*c)
sx#=object position x(obj)+(sin(angy#)*cos(angx#)*prtsys(num).speed)
sy#=object position y(obj)-(sin(angx#)*prtsys(num).speed)
sz#=object position z(obj)+(cos(angy#)*cos(angx#)*prtsys(num).speed)
sx#=sx#+prtsys(num).grav.x
sy#=sy#+prtsys(num).grav.y
sz#=sz#+prtsys(num).grav.z
size#=prtsys(num).sizei+(prtsys(num).sizep*prtsys(num).lifecount)
position object obj,sx#,sy#,sz#
scale object obj,size#,size#,1
set alpha mapping on obj,prtsys(num).alpha
if prtsys(num).lifec>prtsys(num).life
prtsys(num).lifec=prtsys(num).lifec*0
size#=prtsys(num).sizei
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
endif
set object to camera orientation obj
next c
next num
endfunction
`Functions
function zp_freeobject()
repeat
inc i
until object exist(i)=0
endfunction i
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
endfunction token$
`UDTs
type vec3
x as float
y as float
z as float
endtype
type tprtsys
objc as string
pos as vec3
life as integer
lifec as integer
lifecount as integer
lifep as string
count as integer
speed as float
sizei as float
sizep as float
alpha as integer
grav as vec3
endtype
type tprtdat
obj as integer
endtype