; ParticleDemo Effect in PureBasic
; by S.Rings(-CodeGuru-) in 2002
;----------------------------------------------
#scrw = 800
#scrh = 600
#scrd = 32
Structure Particle
X.f
Y.f
velocity.f
speed.f
xoff.f
color.l
heat.f
EndStructure
Num=1000;count of particles
Dim Part.Particle(Num)
Gravity.f=0.65
strength.f=5
For i = 1 To num
Gosub ParticleInit
Next i
;-------- Init all needed Stuff --------
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageBox_ (0,"Can't open DirectX 7 or later", "-Codeguru-", #MB_ICONINFORMATION|#MB_OK)
End
EndIf
If OpenScreen(#scrw,#scrh,#scrd,"ParticleDemo by -CodeGuru-") = 0
MessageBox_ (0,"Could not open screen", "ParticleDemo by -CodeGuru-", #MB_ICONINFORMATION|#MB_OK)
End
EndIf
SetFrameRate(60)
;-------- MainLoop --------
Repeat
ClearScreen(RGB(0,0,0))
ExamineMouse()
musx = MouseX()
musy = MouseY()
If StartDrawing(ScreenOutput())
Gosub ParticleMove
For i = 1 To num
x = Part(i)\X
y = Part(i)\Y
If x >= 0 And y >= 0 And x < #scrw And y < #scrh
Plot(x, y, Part(i)\color)
EndIf
Next i
DrawingMode(1)
DrawText(#scrw/2-100,#scrh/2, "ParticleDemo by -CodeGuru-", RGB(100,100,255))
StopDrawing()
EndIf
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
ParticleInit:
Part(i)\Y = musy;#scrh/2
Part(i)\X = musx;#scrw/2
Part(i)\xoff = Random(100)/100 * -strength + Random(100)/100 * strength
Part(i)\velocity = 0.5
Part(i)\speed = Random(100)/100 * 15
t=Random(55)
Part(i)\color = RGB(200+t,200+t,200+t)
Return
ParticleMove:
For i = 1 To num
Part(i)\speed = (Part(i)\speed + Part(i)\velocity) - gravity
Part(i)\Y = (Part(i)\Y - Part(i)\speed)
Part(i)\X = Part(i)\X + Part(i)\xoff
Part(i)\heat = Part(i)\heat + 3
If Part(i)\Y > #scrh Or Part(i)\X > #scrw
Gosub ParticleInit:
EndIf
Next i
Return
Its a long way to the top if you wanna .....CodeGuru
Restored from previous forum. Originally posted by fred.
This is a Rings code error. WindowMouseX() is intended to runs when a WINDOW is used. If it runs here, it's a luck and willn't run on other OS. When you use the fullscreen mode, use InitMouse()/ExamineMouse()/MouseX()/MouseY(). This is NOT a debugger bug. Please always enable debugger when developping.
Restored from previous forum. Originally posted by Rings.
The Problem only is that i have used a (Pixel)-skeleton from MrVain to test it.
I never use MessageBox_ nor WindowMouseX in my code.But please forgive me, this is a fast 15 minutes port from VB.
Its a long way to the top if you wanna .....CodeGuru