It makes some pretty neat effects but it's definitely not a random particle generator. I don't know why, I guess this is because I am unable to generate a random float. How would I make a Random float, anyway?
Code: Select all
If Not InitSprite()
End
EndIf
Declare Stars(count.l)
mainWindow = OpenWindow(#PB_Any, 0,0,500,500,"Failed Starfield", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(mainWindow), 0,0,500,500,1,0,0)
Repeat : Delay(1)
eventID = WaitWindowEvent(1)
ClearScreen(RGB(0,0,0))
Stars(2000)
FlipBuffers()
Until eventID = #PB_Event_CloseWindow
Procedure Stars(count.l)
Structure obj
a.f
x.l
layer.b
y.l
speed.f
EndStructure
Static Dim Star.obj(1)
Static initiated.l,sprite0,sprite1,sprite2, sprite3, circumference
ReDim Star.obj(count.l)
If initiated.l = #True
For y = 0 To count.l-1
If Star(y)\x <= 490 And Star(y)\x >= 10 And Star(y)\y <= 490 And Star(y)\y >= 10
Star(y)\x = Star(y)\x + (Star(y)\speed * Cos(Star(y)\a.f))
Star(y)\y = Star(y)\y + (Star(y)\speed * Sin(Star(y)\a.f))
Else
Star(y)\a = 0.01 + Random(360) / 47.123
Star(y)\speed = 1+Random(10)
Star(y)\x = 250
Star(y)\y = 250
EndIf
If Star(y)\layer = 0 : DisplaySprite(sprite0,Star(y)\x, Star(y)\y)
ElseIf Star(y)\layer = 1 : DisplaySprite(sprite1,Star(y)\x, Star(y)\y)
ElseIf Star(y)\layer = 2 : DisplaySprite(sprite2,Star(y)\x, Star(y)\y)
ElseIf Star(y)\layer = 3 : DisplaySprite(sprite3,Star(y)\x, Star(y)\y)
EndIf
Next y
Else
sprite0 = CreateSprite(#PB_Any, 2,2)
StartDrawing(SpriteOutput(sprite0)) : Box(0,0,2,2,RGB(255,255,255)) : StopDrawing()
sprite1 = CreateSprite(#PB_Any, 2,2)
StartDrawing(SpriteOutput(sprite1)) : Box(0,0,2,2,RGB(200,200,200)) : StopDrawing()
sprite2 = CreateSprite(#PB_Any, 2,2)
StartDrawing(SpriteOutput(sprite2)) : Box(0,0,2,2,RGB(150,150,150)) : StopDrawing()
sprite3 = CreateSprite(#PB_Any, 2,2)
StartDrawing(SpriteOutput(sprite3)) : Box(0,0,2,2,RGB(100,100,100)) : StopDrawing()
For z = 0 To count.l-1
Star(z)\layer = Random(3)
Star(z)\speed = 0.1+Random(10)
Star(z)\a = 0.01 + Random(360) / 47.123
Next z
initiated.l = #True
EndIf
EndProcedure

