It will close only if you press the right mouse button, but you can press the left button as many times as you want, at least, in my pc...
Here's a new example with gravity.
Code: Select all
InitMouse()
InitSprite()
Structure mydot
x.f
y.f
u.f
v.f
life.f
gr.b
EndStructure
NewList dot.mydot()
id=OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered,"Boom")
OpenWindowedScreen(id,0,0,640,480,0,0,0)
Repeat
ExamineMouse()
If MouseButton(1) And mousepress=0
mousepress=1
For g=0 To 199
AddElement(dot())
angle.f=Random(359)*3.141592/180
dot()\life=1+Random(254)
dot()\u=Cos(angle)*g/(dot()\life*50)
dot()\v=Sin(angle)*g/(dot()\life*50)
dot()\x=MouseX()+dot()\u*(g-100)
dot()\y=MouseY()+dot()\v*(g-100)
dot()\gr=-32
Next g
ElseIf MouseButton(1)=0:mousepress=0:EndIf
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
Plot(MouseX(),MouseY(),255)
ForEach dot()
dot()\gr=dot()\gr+1
dot()\x=dot()\x+dot()\u*dot()\life
dot()\y=dot()\y+dot()\v*dot()\life+dot()\gr/10
If dot()\x=>0 And dot()\x<=639 And dot()\y=>0 And dot()\y<=479
c=dot()\life
c=c+c<<8+c<<16
Plot(dot()\x,dot()\y,c):EndIf
dot()\life=dot()\life-1:If dot()\life<=0:DeleteElement(dot()):EndIf
Next
StopDrawing()
FlipBuffers()
Until MouseButton(2)
I put the \gr field in the structure. Normally it wouldn't be necessary, but the maths got kind of confused...
But it's not that hard:
~First you put the particles at the mouse position. (\x and \y)
~Then you set their x speed (\u) and y speed (\v). Use Sin and Cos to make to do that using an angle value.
~Last, you have a \life field that diminishes till it reaches zero, then the
particle is deleted.
If you look my code you will see I do a lot of other crazy things:
dot()\u=Cos(angle)*g/(dot()\life*50)
dot()\x=dot()\x+dot()\u*dot()\life
You don't need to make things so complicated, I just made this way to get a random result. Try this code, you will understand it better:
Code: Select all
InitMouse()
InitSprite()
Structure mydot
x.f
y.f
u.f
v.f
life.f
EndStructure
NewList dot.mydot()
id=OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered,"Boom")
OpenWindowedScreen(id,0,0,640,480,0,0,0)
Repeat
ExamineMouse()
If MouseButton(1) And mousepress=0
mousepress=1
For g=0 To 199
AddElement(dot())
angle.f=Random(359)*3.141592/180
dot()\life=1+Random(254)
dot()\u=Cos(angle)*random(128)/64
dot()\v=Sin(angle)*random(128)/64
dot()\v=dot()\v-2 ;this will make it go up
dot()\x=MouseX()
dot()\y=MouseY()
Next g
ElseIf MouseButton(1)=0:mousepress=0:EndIf
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
Plot(MouseX(),MouseY(),255)
ForEach dot()
dot()\x=dot()\x+dot()\u
dot()\y=dot()\y+dot()\v
dot()\v=dot()\v+0.05
If dot()\x=>0 And dot()\x<=639 And dot()\y=>0 And dot()\y<=479
c=dot()\life
c=c+c<<8+c<<16
Plot(dot()\x,dot()\y,c):EndIf
dot()\life=dot()\life-1:If dot()\life<=0:DeleteElement(dot()):EndIf
Next
StopDrawing()
FlipBuffers()
Until MouseButton(2)
See, you don't even need the \gr field, just increase the \v (which moves the
particle vertically).
