Microsoft Small Basic

Program Listing: GPZ070
' Krueg -- Starfield -- Sept. 2012

Delay = 60 'Delay for smooth framrate
StarQty = 80 'Number of stars, Too many and it slows the program
SetupWindow()
CreateStars()

While ("True")
MoveStars()
RefreshRate() 'Comment out this line to see the jerkiness of the array proccessing
EndWhile

Sub RefreshRate
While Clock.ElapsedMilliseconds < FrameRate
EndWhile
FrameRate = Clock.ElapsedMilliseconds + Delay
EndSub

Sub MoveStars
For i = 1 To StarQty
StarY[i] = StarY[i] + StarHeight[i] * 1.5
If StarY[i] > gh Then
StarY[i] = StarY[i] - gh
StarX[i] = Math.GetRandomNumber(gw - 10) + 5
EndIf
Shapes.Move(Star[i],StarX[i],StarY[i]) 'Checking which moves smother, Shapes.Move or Shapes.Animate
'Shapes.Animate(Star[i],StarX[i],StarY[i],0)
EndFor
EndSub

Sub CreateStars
For i = 1 To StarQty
GraphicsWindow.PenColor = "White"
GraphicsWindow.BrushColor = "White"
StarWidth[i] = Math.GetRandomNumber(2)
If i < (StarQty * .9) Then
StarHeight[i] = Math.GetRandomNumber(3) 'Create more small stars than big
Else
StarHeight[i] = Math.GetRandomNumber(4)+4
EndIf
Star[i] = Shapes.AddEllipse(StarWidth[i],StarHeight[i])
Shapes.SetOpacity(Star[i],StarHeight[i]*5+50)
StarX[i] = Math.GetRandomNumber(gw - 10) + 5
StarY[i] = Math.GetRandomNumber(gh)
Shapes.Move(Star[i],StarX[i],StarY[i])
EndFor
EndSub

Sub SetupWindow
gw = 800
gh = 600
GraphicsWindow.Top = 5
GraphicsWindow.Left = 5
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "Black"
EndSub