'Importsステートメントで名前空間の参照を簡単にします。
Imports System.Drawing
Imports System.Windows.Forms
Imports Wakaba

Module Game

    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 'X座標
        Dim Y As Integer 'Y座標
        Dim AddX As Integer  'X移動量
        Dim AddY As Integer 'Y移動量
    End Structure

    Private Const MAPCHIP_SIZE As Integer = 32
    Private Const SCROLL_SPEED As Integer = 4 'スクロールスピード

    Dim mintFps As Integer 'fps計測用
    Dim mintSkip As Integer 'フレームスキップ計測用

    Private WithEvents t As Wakaba.GameTimer

    'オブジェクト変数を宣言します。
    Private w As Wakaba.Helper

    Sub Main()

        Try
            Dim objRnd As New Random
            Dim intRnd As Integer
            Dim intScroll As Integer = 0

            Dim intRoll As Integer = 0
            Dim Position(STAR_MAX) As StarPos

            Dim intBackFps As Integer
            Dim intBackSkip As Integer

            w = New Wakaba.Helper
            t = New Wakaba.GameTimer

            w.Initialize()

            'fps表示用スプライトを作成する
            w.SpriteCreate("fps", 128, 32)
            w.SpritePosition("fps", 0, 0, 0)
            w.SpriteShow("fps")

            w.SpriteCreate("マップチップ", My.Resources.map, Helper.TransparentColor.None)

            w.SpriteCreate("背景1", 640, 480)
            w.SpriteShow("背景1")

            w.SpriteCreate("背景2", 640, 480)
            w.SpriteShow("背景2")

            'マップチップを作成する
            For i As Integer = 0 To 14
                For j As Integer = 0 To 19
                    intRnd = objRnd.Next(0, 3)
                    w.SpriteCopy("背景1", CShort(j * MAPCHIP_SIZE), CShort(i * MAPCHIP_SIZE), "マップチップ", intRnd * MAPCHIP_SIZE, 0, MAPCHIP_SIZE, MAPCHIP_SIZE)
                Next
            Next
            w.SpriteCopy("背景2", 0, 0, "背景1", 0, 0, 640, 480)

            '星を作成する
            w.SpriteCreate("星", My.Resources.star, Helper.TransparentColor.PictureTopLeft)
            For i As Integer = 1 To STAR_MAX
                w.SpriteCreate("星" & i.ToString, "星", 0, 0, 64, 64)
                w.SpriteHitAdd("星" & i.ToString, "当り星", 0, 0, 64, 64)

                objRnd = 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

            'fps計測タイマー設定
            t = New Wakaba.GameTimer
            t.Interval = 1000
            t.TimerStart()

            Do
                'スクリーン変更を判定する
                If w.KeyPush(Helper.KeyCodes.CodeZ) Then
                    w.ScreenChange(Helper.ScreenMode.Full)
                ElseIf w.KeyPush(Helper.KeyCodes.CodeX) Then
                    w.ScreenChange(Helper.ScreenMode.Window)
                End If

                '星を移動する
                For j As Integer = 1 To STAR_MAX

                    Dim info As Helper.SpriteInfo = w.SpriteInformation("星" & j.ToString)

                    If info.X < 0 Then
                        Position(j).AddX = STAR_SPEED
                    End If

                    If 640 - 64 < info.X Then
                        Position(j).AddX = -STAR_SPEED
                    End If

                    If info.Y < 0 Then
                        Position(j).AddY = STAR_SPEED
                    End If

                    If 480 - 64 < info.Y Then
                        Position(j).AddY = -STAR_SPEED
                    End If

                    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.SpritePosition("背景1", STAR_MAX + 1, intScroll, 0)
                w.SpritePosition("背景2", STAR_MAX + 1, intScroll - 640, 0)

                intScroll += SCROLL_SPEED
                If intScroll > 640 Then
                    intScroll = 0
                End If

                'fps表示
                If mintFps = intBackFps And mintSkip = intBackSkip Then
                Else
                    Dim msg As String = "fps" & mintFps.ToString & " skip" & mintSkip.ToString

                    w.SpriteFillColor("fps", Color.FromArgb(0))
                    w.SpriteText("fps", msg, 0, 0, "MS ゴシック", 16, FontStyle.Bold, Brushes.Black)

                    intBackFps = mintFps
                    intBackSkip = mintSkip
                End If

                w.ScreenRefresh(True)

            Loop While Not w.WindowClosing And Not w.KeyPush(Helper.KeyCodes.CodeEscape)

            w.ScreenChange(Helper.ScreenMode.Window)

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

        t.Dispose()
        w.Dispose()

    End Sub

    Private Sub t_Tick() Handles t.Tick

        'fps表示
        If w IsNot Nothing Then

            mintFps = w.ScreenFpsCount
            mintSkip = w.ScreenFpsSkipCount

            w.ScreenFpsCount = 0
            w.ScreenFpsSkipCount = 0
        End If

    End Sub

End Module