VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "StarField"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Private Type oneStar
    R As Integer
    G As Integer
    B As Integer
    Stage As Integer
    DestX As Integer
    DestY As Integer
    SrcX As Integer
    SrcY As Integer
    X As Integer
    Y As Integer
End Type

Private Type userStar
    Colour As Long
    X As Long
    Y As Long
End Type

Private A As Integer
Private Stars() As oneStar

Private Const Def_Stars = 500 'amt. of stars that will show up if at 0 when enabled.

'below is some other junk that class-builder put in it...*sigh* \/\/\/\/
'
'
'BELOW IS AUTO-INSERTED JUNK
'
'
'local variable(s) to hold property value(s)
Private mvarEnabled As Boolean 'local copy
Private mvarNumStars As Integer 'local copy
Private mvarcurStarData As userStar 'local copy
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent AutoRedraw[(arg1, arg2, ... , argn)]
Public Event AutoRedraw()
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent EnbStateChange[(arg1, arg2, ... , argn)]
Public Event EnbStateChange()
Private mvarColourLow As Long 'local copy
Private mvarColourHigh As Long 'local copy
Public Property Let ColourHigh(ByVal vData As Long)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.ColourHigh = 5
    mvarColourHigh = vData
End Property


Public Property Get ColourHigh() As Long
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.ColourHigh
    ColourHigh = mvarColourHigh
End Property



Public Property Let ColourLow(ByVal vData As Long)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.ColourLow = 5
    mvarColourLow = vData
End Property


Public Property Get ColourLow() As Long
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.ColourLow
    ColourLow = mvarColourLow
End Property

Public Property Get curStarData() As userStar
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.curStarData
    curStarData = mvarcurStarData
End Property

Public Function GetStarData(StarNum As Integer)
'    Let curStarData = Stars(StarNum)
    curStarData.Colour = RGB(Stars(StarNum).R, Stars(StarNum).G, Stars(StarNum).B)
    curStarData.X = Stars(StarNum).X
    curStarData.Y = Stars(StarNum).Y
End Function

Public Sub Redraw() 'this is a method used to manually (as of yet there is no auto) update the scene. Try using Timer, GetTickCount, or the Timer Control to use the class module.
Dim V As Integer
    If mvarEnabled = False Then Exit Sub

    For V = 1 To A
        UpdStar V
    Next V
End Sub

Public Property Let NumStars(ByVal vData As Integer)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.NumStars = 5
    mvarNumStars = vData
End Property


Public Property Get NumStars() As Integer
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.NumStars
    NumStars = mvarNumStars
End Property

Public Property Let Enabled(ByVal vData As Boolean)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Enabled = 5
    mvarEnabled = vData
    RaiseEvent EnbStateChange
End Property


Public Property Get Enabled() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Enabled
    Enabled = mvarEnabled
End Property

Function Initialize()
Dim B As Integer: Dim C As Integer
    
    A = mvarNumStars: If A = 0 Then A = Def_Stars
    Let NumStars = A
    
    ReDim Preserve Stars(1 To A) As oneStar
    For B = 1 To A
        NewStar B
    Next B
End Function

Function UpdStar(StarNum As Integer)
Dim C
    If Stars(StarNum).Stage = 255 Then
        NewStar StarNum
    End If
    C = StarNum
        
    Inc Stars(C).Stage 'my funct. shorthand for Stars(C).Stage = Stars(C).Stage + 1
    Stars(C).R = GetR(mvarColourLow) * (255 - Stars(C).Stage) + GetR(mvarColourHigh) * (Stars(C).Stage) / 255
    Stars(C).G = GetG(mvarColourLow) * (255 - Stars(C).Stage) + GetG(mvarColourHigh) * (Stars(C).Stage) / 255
    Stars(C).B = GetB(mvarColourLow) * (255 - Stars(C).Stage) + GetB(mvarColourHigh) * (Stars(C).Stage) / 255
    
    Stars(C).X = Stars(C).X + Round((Stars(C).DestX - Stars(C).SrcX) * (1 / 255), 0)
    Stars(C).Y = Stars(C).Y + Round((Stars(C).DestY - Stars(C).SrcY) * (1 / 255), 0)
    
End Function

Function NewStar(B As Integer)
Dim C As Integer
    
    Stars(B).Stage = 0
    Stars(B).R = GetR(mvarColourLow)
    Stars(B).G = GetG(mvarColourLow)
    Stars(B).B = GetB(mvarColourLow)
    Stars(B).SrcX = Int(Screen.Width / Screen.TwipsPerPixelX / 2)
    Stars(B).SrcY = Int(Screen.Height / Screen.TwipsPerPixelY / 2)
        
    C = Int(Rnd * 3) + 1
        
    If C = 0 Then
        Stars(B).DestX = 0
        Randomize
        Stars(B).DestY = Int(Rnd * ((Screen.Height / Screen.TwipsPerPixelY) - 1)) + 1
    ElseIf C = 2 Then
        Randomize
        Stars(B).DestX = Screen.Width / Screen.TwipsPerPixelX
        Stars(B).DestY = Int(Rnd * ((Screen.Height / Screen.TwipsPerPixelY) - 1)) + 1
    ElseIf C = 1 Then
        Randomize
        Stars(B).DestX = Int(Rnd * ((Screen.Width / Screen.TwipsPerPixelX) - 1)) + 1
        Stars(B).DestY = 0
    ElseIf C = 3 Then
        Randomize
        Stars(B).DestX = Int(Rnd * ((Screen.Width / Screen.TwipsPerPixelX) - 1)) + 1
        Stars(B).DestY = Screen.Height / Screen.TwipsPerPixelX
    End If
End Function

Function Inc(ByRef IncNum As Integer)
    IncNum = IncNum + 1
End Function
Function Dec(ByRef DecNum As Integer)
    DecNum = DecNum - 1
End Function

Function GetR(ByVal pCol As Long) As Byte
   
   GetR = pCol Mod 256

End Function

Function GetG(ByVal pCol As Long) As Byte
    
   pCol = pCol \ 256
   GetG = pCol Mod 256
    
End Function

Function GetB(ByVal pCol As Long) As Byte

    pCol = (pCol \ 256) \ 256
    GetB = pCol Mod 256

End Function

