Attribute VB_Name = "modReadMap"
' Created on 30 March 2005 : 13:30 (Location: The Netherlands)
' Purpose reading a simple file to generate a map.
' Creator: Tom Hofman <tom.hofman@gmail.com>
' Especially posted for VBFORUMS!

Type tBlock
    iX As Long
    iY As Long
End Type

Public tBlockedTile(255) As tBlock

Public Function ReadMap()
    On Error Resume Next
    
    bLoading = True
    
    Dim iCurRow, iChar, iRow(100), Returned, tmpFormula, iRowLenght As Long

    iCurRow = 0
    iChar = 1
    
    Open App.Path & "\map.dat" For Input As #1
        Input #1, iRow(0)
        Input #1, iRow(1)
        Input #1, iRow(2)
        Input #1, iRow(3)
        Input #1, iRow(4)
        Input #1, iRow(5)
        Input #1, iRow(6)
        Input #1, iRow(7)
        Input #1, iRow(8)
        Input #1, iRow(9)
        Input #1, iRow(10)
        Input #1, iRow(11)
        Input #1, iRow(12)
    Close #1
    
    iRowLenght = Len(iRow(0))
    
    Do Until iCurRow > 13
        Returned = Mid(iRow(iCurRow), iChar, 1)
        If Returned = "" Then Returned = 1
        
        If Returned = 2 Then
            tBush(iChar + (iCurRow * iRowLenght)).iX = (iChar - 1) * 16
            tBush(iChar + (iCurRow * iRowLenght)).iY = 0 + Int(iCurRow * 16)
        End If
        
        frmMain.Text1.Text = frmMain.Text1.Text + Returned
        If iChar = iRowLenght Then
            frmMain.Text1.Text = frmMain.Text1.Text + vbNewLine
            iCurRow = iCurRow + 1
            iChar = 1
        Else
            iChar = iChar + 1
        End If
    Loop
    
    bLoading = False
End Function

Public Function DrawMap()
'### Clean frmMain
    form1.screen.Cls
    
'### Draw Blockers
' Note if you don't use all Blocker array element
' it will place the rest on X = 0 and Y = 0
' (So that makes it show at the left top)
    Dim iCur As Long
    Do Until iCur = 255
        BitBlt form1.Picture1.hDC, tBush(iCur).iX, tBush(iCur).iY, 16, 16, Picture2.hDC, 0, 0, vbSrcCopy
        iCur = iCur + 1
    Loop
End Function
