Imports System.ThreadingModule uiGraphics
Dim black As Brush = Brushes.Black
Dim rand As New Random()
Dim UI As Bitmap
'Public iSpeed As Integer = 1
' 0 1 2 3 4 5
Private stars(maxStars, 5) As Integer 'Tracks positon of stars {state, x, y, size, speed, direction}
Public Sub UpdateStars() 'ByRef g As Graphics
If Warping = True Then
WarpEffect()
ElseIf iSpeed <> 0 Then
DrawStars()
'GenStar()
T2.Join()
T2 = New Thread(AddressOf GenStar)
T2.Start()
'MoveStars()
T2.Join()
T2 = New Thread(AddressOf MoveStars)
T2.Start()
drawUI()
'GameView.T2.Join()
'GameView.T2 = New Thread(AddressOf DrawStars)
'GameView.T2.Start()
ElseIf iSpeed = 0 Then
DrawStars()
End If
End Sub
Public Sub Turn()
'T1.Join()
'T1 = New Thread(AddressOf ResetView)
'T1.Start()
ResetView()
End Sub
Public Sub Warp()
'Call starfield reset
End Sub
Private Sub ResetView() 'Used when switching between sectors/turning
T2.Join()
T2 = New Thread(AddressOf VirtualUpdateStars)
T2.Start()
T2.Join()
End Sub
Private Sub VirtualUpdateStars()
Dim angle As Double
For count = 0 To maxStars - 1 Step 1 '"Discards" all stars
stars(count, 0) = 0
Next
For ticker = 0 To 1000
GenStar()
For count = 0 To maxStars - 1 Step 1
If stars(count, 0) = 1 Then
angle = stars(count, 5) * Math.PI / 180
stars(count, 1) = stars(count, 1) + (Math.Cos(angle) * stars(count, 4) * 3 * (iSpeed + 1))
stars(count, 2) = stars(count, 2) + (Math.Sin(angle) * stars(count, 4) * 3 * (iSpeed + 1))
End If
If stars(count, 1) > 1024 Or stars(count, 1) < 0 Or stars(count, 2) > 780 Or stars(count, 2) < 0 Then
stars(count, 0) = 0
End If
Next
Next
End Sub
Private Sub GenStar() 'Call via T2
Dim count As Short = 0
While (stars(count, 0) = 1 And count < maxStars - 1) 'First empty slot in array
count += 1
End While
stars(count, 1) = xMid
stars(count, 2) = yMid
stars(count, 3) = rand.Next(4) + 1 'Size coefficient
stars(count, 4) = rand.Next(3) + 1 'Speed coefficient
stars(count, 5) = rand.Next(360) 'Angle in degrees, used instead of radians such that array could remain as integers
stars(count, 0) = 1 'star exists
'count = 0
End Sub
Private Sub MoveStars() 'Call via T2
Dim angle As Double
For count = 0 To maxStars - 1 Step 1
If stars(count, 0) = 1 Then
angle = stars(count, 5) * Math.PI / 180
stars(count, 1) = stars(count, 1) + (Math.Cos(angle) * stars(count, 4) * (iSpeed + 1) * iSpeed)
stars(count, 2) = stars(count, 2) + (Math.Sin(angle) * stars(count, 4) * (iSpeed + 1) * iSpeed)
End If
If stars(count, 1) > 1024 Or stars(count, 1) < 0 Or stars(count, 2) > 780 Or stars(count, 2) < 0 Then
stars(count, 0) = 0
End If
Next
End Sub
Private Sub DrawStars() 'Call via T2
Dim dist As Short
Dim size As Short
Dim radius As Short
Dim white As Brush = Brushes.White
Dim g As Graphics = MainGameView.getG
'g.FillRectangle(black, 0, 0, MainGameView.Width, MainGameView.Height)
For count = 0 To maxStars - 1 Step 1
If stars(count, 0) = 1 Then
dist = Math.Sqrt((stars(count, 1) - xMid) ^ 2 + (stars(count, 2) - yMid) ^ 2)
size = stars(count, 3) * dist / 50
radius = size / 2
g.FillEllipse(white, stars(count, 1) - radius, stars(count, 2) - radius, size, size)
End If
Next
drawUI()
End Sub
Private Sub WarpEffect()
Dim black As Brush = Brushes.Black
Dim p As Pen
MainGameView.getG().FillRectangle(black, 0, 0, MainGameView.Width, MainGameView.Height)
'Gen(Star)
T2.Join()
T2 = New Thread(AddressOf GenStar)
T2.Start()
'Move(stars)
T2.Join()
T2 = New Thread(AddressOf MoveStars)
T2.Start()
For count = 0 To maxStars - 1 Step 1
If stars(count, 0) = 1 Then
p = New Pen(Color.FromArgb(rand.Next(254), rand.Next(254), rand.Next(254), rand.Next(254)), rand.Next(5) + 5)
MainGameView.getG().DrawLine(p, xMid, yMid, stars(count, 1), stars(count, 2))
End If
Next
End Sub
Public Sub makeUI()
Dim g As Graphics
g = MainGameView.CreateGraphics()
UI = My.Resources.cockpit
UI.MakeTransparent(Color.Fuchsia)
g.DrawImage(UI, 0, 0)
End Sub
Public Sub drawUI()
makeUI()
End Sub
End Module