i made a 2d particle system.
Here are the functions
type ParticI
x as float
y as float
Rot as float
RS as float
Grav as float
xs as float
ys as float
SN as integer
Life as integer
xr as float
yr as float
alp as float
alps as float
endtype
Dim PartI(-1) as ParticI
`put the above at the top of your program
`incase your program is a no-media. Good for simple sparks
Function MakeRectIm(ImNum as integer, Width as integer, Height as integer, Color as Dword)
create bitmap 32, Width, Height
ink Color, 0
box 0,0,Width, Height
get image ImNum, 0,0, Width, Height, 3
delete bitmap 32
endfunction
FUNCTION Make2dParticlesA(x as integer,y as integer,Grav as float, Am as word,Angle as float,AngRan as float,pSpeed as float,SpeedRan as float,SN as integer,Life as integer,xr as float,yr as float,RotSpeed as float,Fade as float,Alpha as byte)
op = array count(PartI()) + 1
array insert at bottom PartI(), Am
np = array count(PartI())
offset sprite SN, sprite width(SN) / 2, sprite height(SN) / 2
hide sprite SN
for i = op to np
PartI(i).x = x
PartI(i).y = y
PartI(i).Grav = Grav
fSpeed# = (pSpeed + (rnd(SpeedRan*100)/100))
PartI(i).xs = sin(Angle+((rnd(AngRan*100)/100) - (AngRan / 2))) * fSpeed#
PartI(i).ys = -cos(Angle+((rnd(AngRan*100)/100) - (AngRan / 2))) * fSpeed#
PartI(i).SN = SN
PartI(i).Life = Life
PartI(i).xr = xr
PartI(i).yr = yr
PartI(i).RS = RotSpeed
PartI(i).alps = Fade
PartI(i).alp = Alpha
next i
endfunction
Function Make2dParticles(x as integer,y as integer,Grav as float, Am as word,xlp as float,ylp as float,xhp as float,yhp as float,SN as integer,Life as integer,xr as float,yr as float,RotSpeed as float,Fade as float,Alpha as byte)
op = array count(PartI()) + 1
array insert at bottom PartI(), Am
np = array count(PartI())
offset sprite SN, sprite width(SN) / 2, sprite height(SN) / 2
hide sprite SN
for i = op to np
PartI(i).x = x
PartI(i).y = y
PartI(i).Grav = Grav
PartI(i).xs = (rnd((xhp*100)-(xlp*100))+(xlp*100))/100
PartI(i).ys = (rnd((yhp*100)-(ylp*100))+(ylp*100))/100
PartI(i).SN = SN
PartI(i).Life = Life
PartI(i).xr = xr
PartI(i).yr = yr
PartI(i).RS = RotSpeed
PartI(i).alps = Fade
PartI(i).alp = Alpha
next i
endfunction
FUNCTION Show2dParticles(xscroll as integer, yscroll as integer)
for i = 0 to array count(PartI())
rotate sprite PartI(i).SN, PartI(i).Rot
set sprite alpha PartI(i).SN, int(PartI(i).alp)
Paste sprite PartI(i).SN,PartI(i).x-xscroll,PartI(i).y-yscroll
next i
ENDFUNCTION
FUNCTION Update2dParticles()
For i = 0 to array count(PartI())
if i <= array count(PartI())
del = 0
inc PartI(i).x, (rnd((PartI(i).xr*2))-PartI(i).xr)
inc PartI(i).y, (rnd((PartI(i).yr*2))-PartI(i).yr)
inc PartI(i).x, PartI(i).xs
inc PartI(i).y, PartI(i).ys
inc PartI(i).ys,PartI(i).grav
PartI(i).Rot = wrapvalue(PartI(i).Rot + PartI(i).RS)
dec PartI(i).alp, PartI(i).alps
if PartI(i).alp > 255 or PartI(i).alp <= 0
array delete element PartI(), i
del = 1
endif
if del <> 1
if PartI(i).Life > -1
dec PartI(i).Life
if PartI(i).Life = 0
array delete element PartI(), i
endif
endif
endif
endif
next
ENDFUNCTION
FUNCTION XShift2dParticles(xamount as float, SprNum as integer)
if SprNum = 0 :if array count(PartI()) > -1 : for i = 0 to array count(PartI()) : inc PartI(i).x, xamount : next i
endif : else : for i = 0 to array count(PartI()) : if PartI(i).SN = SprNum :inc PartI(i).x, xamount : endif
next i : endif
endfunction
FUNCTION YShift2dParticles(yamount as float, SprNum as integer)
if SprNum = 0 :if array count(PartI()) > -1 : for i = 0 to array count(PartI()) : inc PartI(i).y, yamount : next i
endif : else : for i = 0 to array count(PartI()) : if PartI(i).SN = SprNum :inc PartI(i).y, yamount : endif
next i : endif
endfunction
FUNCTION BoundrysTo2dParticles(Left as integer,Top as integer,Right as integer,Bot as integer,SprNum as integer)
if SprNum <> 0 : if array count(PartI()) > -1
for i = 0 to array count(PartI()) : if i <= array count(PartI()) : if PartI(i).SN = SprNum
if PartI(i).x < Left or PartI(i).y < top or PartI(i).x > Right or PartI(i).y > Bot
array delete element PartI(), i : endif : endif : endif : next : endif : else
if array count(PartI()) > -1 : for i = 0 to array count(PartI()) : if i <= array count(PartI())
if PartI(i).x < Left or PartI(i).y < top or PartI(i).x > Right or PartI(i).y > Bot
array delete element PartI(), i : endif : endif : next : endif : endif
endfunction
FUNCTION Delete2dParticles(SprNum as integer)
if array count(PartI()) > -1 : for i = 0 to array count(PartI()) : if i <= array count(PartI()) : if SprNum <> 0
if PartI(i).SN = SprNum : array delete element PartI(), i : endif : else :array delete element PartI(), i
endif : endif : next i : endif
endfunction
Here is a parameter description for the Make2dParticles function.
x xpos of were the particles start
y same as above but y
Grav Gravity of the particle. Good for a spark
Am Amount of particles released in this blast
xlp and xhp A random x power will be chosen between these ranges. Same with ylp and yhp.
It works with up to two decimals because rnd only works with integers
SN the sprite number for the particle
Life How many updates the particle will last. -1 will disable this
xr and yr basicly the chaos of each dimension for the particle
RotSpeed How fast the particle will rotate
Fade How fast the particl will fade
Alpha The start alpha of the particle. 255 would be solid, and 0 completly transparent
and for Make2dParticlesA
x xpos of were the particles start
y same as above but y
Grav Gravity of the particle. Good for a spark
Am Amount of particles released in this blast
Angle The angle
AngleRan How big the range is for a randomm angle
Speed How fast the particle will go
SpeedRan A random speed added
SN the sprite number for the particle
Life How many updates the particle will last. -1 will disable this
xr and yr basicly the chaos of each dimension for the particle
RotSpeed How fast the particle will rotate
Fade How fast the particl will fade
Alpha The start alpha of the particle. 255 would be solid, and 0 completly transparent
The two parameters for Draw2dParticles are the xscroll and yscroll. incase you're making a sidescroller.
The parameters for xshift2dparticles are the amount that you want to move the particles, and the sprite number of the particles that you're moving
e.g.
SMOKE = 1
load image "smoke.png", SMOKE
sprite SMOKE, 0,0,SMOKE
XShift2dParticles(1,
SMOKE)
This command is good for applying a wind.
A sprite number of 0 would cause it to affect all particles.
Vice verca with YShift2dParticles, Delete2dparticles, and BoundrysTo2dParticles.
BoundrysTo2dParticles will delete all particles with the sprite number you specify if it is out of the boundrys you specify.
Delete2dparticles will delete all particles with the sprite number you specify.
I attached a zip with an example how to use this.
(in the example, use the arrow keys for wind, spacebar to delete all the smoke)
Tell me of any bugs and plase give me suggestions.
Cave Man