Imports System.Drawing
Imports System.Windows.Forms
Imports Wakaba

Module Module1

    Private Const STAR_MAX As Integer = 50        
    Private Const STAR_SPEED As Integer = 4        '̈ړx
    Private Const STAR_ROLL_SPEED As Integer = 8   '̉]x

    Private Structure StarPos
        Dim X As Integer
        Dim Y As Integer
        Dim AddX As Integer  'Xړ
        Dim AddY As Integer 'Yړ
    End Structure

    Private w As Wakaba.Helper

    Sub Main()

        Try
            Dim i As Integer
            Dim j As Integer
            Dim intRoll As Integer = 0
            Dim objWallName As Helper.HitName
            Dim Position(STAR_MAX) As StarPos

            w = New Wakaba.Helper
            w.Initialize()

            'wi쐬
            w.SpriteCreate("wi", My.Resources.wall, Helper.TransparentColor.None)
            w.SpritePosition("wi", STAR_MAX + 1, 0, 0)
            w.SpriteHitAdd("wi", "Ǐ", 0, -32, 640, 32)
            w.SpriteHitAdd("wi", "ljE", 640, 0, 32, 480)
            w.SpriteHitAdd("wi", "lj", 0, 480, 640, 32)
            w.SpriteHitAdd("wi", "Ǎ", -32, 0, 32, 480)
            w.SpriteShow("wi")

            '쐬
            w.SpriteCreate("", My.Resources.star, Helper.TransparentColor.PictureTopLeft)
            For i = 1 To STAR_MAX
                w.SpriteCreate("" & i.ToString, "", 0, 0, 64, 64)
                w.SpriteHitAdd("" & i.ToString, "萯", 0, 0, 64, 64)

                Dim objRnd As Random = New Random(i)
                Position(i).X = objRnd.Next(0, 640 - 64)
                Position(i).Y = objRnd.Next(0, 480 - 64)
                Position(i).AddX = STAR_SPEED
                Position(i).AddY = STAR_SPEED

                w.SpritePosition("" & i.ToString, i, Position(i).X, Position(i).Y)
                w.SpriteTransparent("" & i.ToString, 128)

                w.SpriteShow("" & i.ToString)
            Next

            
            Do

                For j = 1 To STAR_MAX

                    For Each objWallName In w.SpriteHitList("" & j.ToString)

                        Select Case objWallName.AreaName
                            Case "Ǐ"
                                Position(j).AddY = STAR_SPEED
                            Case "ljE"
                                Position(j).AddX = -STAR_SPEED
                            Case "lj"
                                Position(j).AddY = -STAR_SPEED
                            Case "Ǎ"
                                Position(j).AddX = STAR_SPEED
                        End Select

                    Next

                    Position(j).X += Position(j).AddX
                    Position(j).Y += Position(j).AddY

                    w.SpriteRotation("" & j.ToString, intRoll)
                    w.SpritePosition("" & j.ToString, j, Position(j).X, Position(j).Y)
                Next

                If intRoll > 360 Then
                    intRoll = 0
                Else
                    intRoll += STAR_ROLL_SPEED
                End If

                w.ScreenRefresh(True)

            Loop While Not w.WindowClosing

        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace)
        End Try

        w.Dispose()

    End Sub

End Module