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        '星の移動速度
    Private Const STAR_ROLL_SPEED As Integer = 8   '星の回転速度

    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()

            '背景を作成する
            w.SpriteCreate("背景", My.Resources.wall, Helper.TransparentColor.None)
            w.SpritePosition("背景", STAR_MAX + 1, 0, 0)
            w.SpriteHitAdd("背景", "当り壁上", 0, -32, 640, 32)
            w.SpriteHitAdd("背景", "当り壁右", 640, 0, 32, 480)
            w.SpriteHitAdd("背景", "当り壁下", 0, 480, 640, 32)
            w.SpriteHitAdd("背景", "当り壁左", -32, 0, 32, 480)
            w.SpriteShow("背景")

            '星を作成する
            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 "当り壁右"
                                Position(j).AddX = -STAR_SPEED
                            Case "当り壁下"
                                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