spawn some bubbles from the mouse. Needed it for my game and thought I'd share the function, figured others would find use for this simple particle effect. The bubbles will start small then expand as they rise.
The image I used was a 64x64 bubble png.
#CONSTANT BUBBLE_COUNT = 150
Type ParticleEntity
baseY as integer
posX as float
posY as float
ang as float
vel as float
EndType
dim bubbles(1, BUBBLE_COUNT) as ParticleEntity
load image "H:\Programming\Dark Basic\DBPro Source\angry fish\B64.png", 1, 1
initializeBubbles(1)
sync on
sync rate 60
ink rgb(255,0,0),0
do
cls
doBubbles(mousex(), mousey())
sync
loop
rem image number to use for the bubbles
function initializeBubbles(imgBubble)
sprite 1, 0, 0, imgBubble : hide sprite 1 : set sprite alpha 1, 96
for i = 2 to BUBBLE_COUNT
clone sprite 1, i
bubbles(1, i).posY = 0-rnd(screen height())
next i
endfunction
rem x,y is where new bubbles spawn
function doBubbles(x, y)
for i = 1 to BUBBLE_COUNT
bubbles(1, i).posX = bubbles(1, i).posX + sin(bubbles(1, i).ang)*bubbles(1, i).vel
bubbles(1, i).posY = bubbles(1, i).posY - cos(bubbles(1, i).ang)*bubbles(1, i).vel
rem if bubble rose beyond the top of the screen, reinitialize it.
if bubbles(1, i).posY < -64
bubbles(1, i).posX = x
bubbles(1, i).posY = y
bubbles(1, i).baseY = bubbles(1, i).posY
bubbles(1, i).ang = rnd(30)-15
bubbles(1, i).vel = (rnd(20)+10.0) / 10.0
endif
rem Scale the bubble sprites.
rem Bubbles will start with a size of 0 and reach their full
rem actual size once they rise 420px from their originating point
dy = abs(bubbles(1, i).baseY - bubbles(1, i).posY)
size# = (dy / 420.0) * 100.0
if size# > 100 then size# = 100.0
if size# < 0 then size# = 0
scale sprite i, size#
rem paste the bubble on screen
paste sprite i, bubbles(1, i).posX, bubbles(1, i).posY
next i
endfunction
