'
'Chapter 1
'Memory Device Context
'
Option Explicit
Public Declare Function TimeGetTime Lib "winmm.dll" () As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
'Constants for the GenerateDC function
'**LoadImage Constants**
Global Const IMAGE_BITMAP As Long = 0
Global Const LR_LOADFROMFILE As Long = &H10
Global Const LR_CREATEDIBSECTION As Long = &H2000
Global Const LR_DEFAULTSIZE As Long = &H40
Global Const KEY_TOGGLED As Integer = &H1
Global Const KEY_DOWN As Integer = &H1000
'****************************************
Global Const SpriteWidth As Long = 50
Global Const SpriteHeight As Long = 50
Global time
Global endmap, i
Global nextmapright, mapright, looploop
Global error
Global DC As Long
Global hBitmap As Long
Public Sub spriteload()
sprnum = 4
iFileNo = FreeFile
'open the file for reading
For z = 1 To 5 'reads all maps and saves them into array
Open "x:\mygame\map(" & z & ").txt" For Input As #iFileNo
For y = 1 To 11
For x = 1 To 15
Input #iFileNo, map0(z, x, y) 'reads map information
Next
Next
Close #iFileNo 'close the file (if you dont do this, you wont be able to open it again!)
Next
z = 0
DeleteGeneratedDC grass(0) 'Generate the two DCs, one for the mask and one for the sprite
DeleteGeneratedDC grass(1)
'generates all sprites (one line!!!)
66
For i = 0 To sprnum
grass(i) = GenerateDC("x:\mygame\grass(" & i & ").bmp") 'png dosent work
Next
'checks for errors and loads up to 10 times
For i = 0 To sprnum
If grass(i) <= 0 Then
error = error + 1
If error = 200 Then Exit Sub
GoTo 66
End If
Next
End Sub
'Deletes a generated DC
Public Function DeleteGeneratedDC(DC As Long) As Long
If DC > 0 Then
DeleteGeneratedDC = DeleteDC(DC)
Else
DeleteGeneratedDC = 0
End If
End Function
'IN: FileName: The file name of the graphics
'OUT: The Generated DC
Public Function GenerateDC(FileName As String) As Long
'Create a Device Context, compatible with the screen
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
Exit Function
End If
'Load the image....BIG NOTE: This function is not supported under NT, there you can not
'specify the LR_LOADFROMFILE flag
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
Exit Function
End If
'Throw the Bitmap into the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
'Delte the bitmap handle object
DeleteObject hBitmap
End Function