Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Blue
        Me.ClientSize = New System.Drawing.Size(704, 470)
        Me.KeyPreview = True
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region


    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


    Public Structure tilesystem
        Public screenx, screeny As Integer
        Public camerax, cameray As Integer
        Public scrollx, scrolly As Integer
        Public worldx, worldy As Integer
        Public world As Char(,)
        Public offsetx, offsety As Integer
        Public Sub initialize()
            screenx = 0
            screeny = 0
            worldx = 0
            worldy = 0
            camerax = 0
            cameray = 0
            offsetx = 0
            offsety = 0
            scrollx = 0
            scrolly = 0
            '20 by 15 for 640 by 480 to scroll it will be 26 by 20
            world = New Char(26, 20) {{"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}, _
                                      {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}}
        End Sub
    End Structure
    Public Structure bimage
        Public imagearray As ArrayList
        Public numframes As Integer
        Public speed As Integer
        Public posx, posy As Integer
        Public Sub initialize()
            numframes = 0
            speed = 0
            posx = 0
            posy = 0
            imagearray = New ArrayList
        End Sub
    End Structure

    Dim graphicobject As Graphics
    Dim aimage As Bitmap
    Dim mimages As ArrayList = New ArrayList
    Dim count As Integer = 0
    Dim lrectangle As New Rectangle(0, 0, 33, 33)
    Dim partimage As Bitmap
    Dim bitmapimage As bimage
    Dim state As Boolean = 0
    Dim avar As Integer = 1
    Dim color As System.Drawing.Color = color.Black
    Dim bcolor As System.Drawing.Color = bcolor.Blue
    Dim atilesystem As tilesystem
    Dim key As Integer = 0

    Dim barray As ArrayList = New ArrayList
    Dim framecount As Integer = 0









    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
        Dim avar As Integer = 0

        'this should be constructor it initializes everything
        bitmapimage.initialize()

        'this should be constructor also
        atilesystem.initialize()

        bitmapimage.numframes = 4

        graphicobject = Me.CreateGraphics
        aimage = Image.FromFile("c:\\dart\tilessmall.bmp")
        'lrectangle.X() += 1
        'If (lrectangle.X() > 640) Then
        'lrectangle.X() = 33
        'End If
        While (count < bitmapimage.numframes)
            partimage = aimage.Clone(New Rectangle(count * 33, 0, 33, 33), Drawing.Imaging.PixelFormat.DontCare)
            bitmapimage.imagearray.Add(partimage)
            partimage.MakeTransparent(color)
            graphicobject.Clear(bcolor)
            count += 1
        End While


        While (avar < 4000)
            atilesystem.camerax += 4

            'graphicobject.DrawImage(partimage, lrectangle)
            tileengine(atilesystem, 640, 480)
            'Sleep(1)
            'count += 1
            'If (count > 8) Then
            'count = 1
            'End If
            avar += 1
        End While
    End Sub

    Public Function tileengine(ByRef atilesystem As tilesystem, ByVal resx As Integer, ByVal resy As Integer)
        Dim tilesizex = 32
        Dim tilesizey = 32
        Dim screensizex As Integer = (resx / tilesizex - 1)
        Dim screensizey As Integer = (resy / tilesizey - 1)
        Dim worldsizex As Integer = 26
        Dim worldsizey As Integer = 20
        Dim y As Integer = 0
        Dim x As Integer = 0
        Dim index As Integer = 0

        'atilesystem.startx = resx / 2
        'atilesystem.starty = resy / 2
        'atilesystem.offsetx = atilesystem.screenx Mod 32
        'atilesystem.offsety = atilesystem.screeny Mod 32
        For y = 0 To screensizey Step 1
            For x = 0 To screensizex Step 1
                index = Val(atilesystem.world(x, y))
                atilesystem.scrollx = atilesystem.camerax / tilesizex
                atilesystem.scrolly = atilesystem.cameray / tilesizey
                atilesystem.offsetx = atilesystem.scrollx & (tilesizex - 1)
                atilesystem.offsety = atilesystem.scrolly & (tilesizey - 1)
                'index into image array to get that tile
                lrectangle.X() = (x * 32) - atilesystem.offsetx
                lrectangle.Y() = (y * 16) - atilesystem.offsety
                graphicobject.DrawImage(bitmapimage.imagearray(index), lrectangle)
            Next
        Next
    End Function

    Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
        '39 left 38 up 39 right 40 down
        If (KeyCode = 39) Then
            key = 39
        End If
    End Sub

End Class
