Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHieght As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal yScr As Long, ByVal dwRop As Long) As Long
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Dim Xpos As Integer
Dim Ypos As Integer
Dim Lstand As String
Dim Cmove As String
Dim Col As Integer
Dim Tickz As Integer
Dim cWidth As Integer
Dim cHeight As Integer
Dim Xaxis As Integer
Dim Yaxis As Integer
Dim Frames As Integer
Private Function GetKey(lngKey As Long) As Boolean
'GetKeyState yung ginawa mong private declare function
If GetKeyState(lngKey&) < 0 Then
'private function inirereturn nya yung val as boolean
GetKey = True
Else
GetKey = False
End If
End Function
Private Sub dMap()
'dito dinadraw nya yung map
BitBlt Form1.hDC, 0, 0, picBack.Width, picBack.Height, picBack.hDC, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Load()
'str for start position ng character
Lstand$ = "down"
'str for move naman ng character
Cmove$ = "stand"
' for yaxis position of the character
Ypos = 110
' for xaxis position of the character
Xpos = 220
End Sub
Private Sub Timer1_Timer()
dMap
'pic.Width default value
cWidth = 19
'pic.Height default value
cHeight = 32
'key for up
If GetKey(vbKeyW) Then
Ypos = Ypos - 1
Yaxis = Yaxis - 1
Cmove$ = "up"
Lstand$ = "up"
End If
' key for down
If GetKey(vbKeyS) Then
Ypos = Ypos + 1
Yaxis = Yaxis + 1
Cmove$ = "down"
Lstand$ = "down"
End If
' key for left
If GetKey(vbKeyA) Then
Xpos = Xpos - 1
Xaxis = Xaxis - 1
Cmove$ = "left"
Lstand$ = "left"
End If
' key for right
If GetKey(vbKeyD) Then
Xpos = Xpos + 1
Xaxis = Xaxis + 1
Cmove$ = "right"
Lstand = "right"
End If
' kapag nag false lahat si cmove$ ay mag eequal sa "stand"
' tapos hanapin nya ngayon yung conditon para kay cmove$
If GetKey(vbKeyW) = False And GetKey(vbKeyS) = False And GetKey(vbKeyA) = False And GetKey(vbKeyD) = False Then
Cmove$ = "stand"
End If
' Make sure the character can't go offscreen.
If Xpos < 5 Then
Xpos = 5
End If
If Xpos > 415 Then
Xpos = 415
End If
If Ypos < 5 Then
Ypos = 5
End If
If Ypos > 195 Then
Ypos = 195
End If
' eto yung nested if para kay cmove$ kapag nag equal siya sa string na "stand" then hanapin nya yung conditon string
' si lstand$ yung mga gagawin nya
If Cmove$ = "stand" Then
If Lstand$ = "up" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, uPic2.hDC, 0, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, uPic1.hDC, 0, 0, vbSrcPaint
End If
If Lstand$ = "down" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, dPic2.hDC, 0, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, dPic1.hDC, 0, 0, vbSrcPaint
End If
If Lstand$ = "left" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, lPic2.hDC, 0, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, lPic1.hDC, 0, 0, vbSrcPaint
End If
If Lstand$ = "right" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, rPic2.hDC, 0, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, rPic1.hDC, 0, 0, vbSrcPaint
End If
End If
'eto naman yung conditon kay cmove$
' yung Tickz ay xSrc
If Cmove$ = "up" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, uPic2.hDC, Tickz, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, uPic1.hDC, Tickz, 0, vbSrcPaint
End If
If Cmove$ = "down" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, dPic2.hDC, Tickz, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, dPic1.hDC, Tickz, 0, vbSrcPaint
End If
If Cmove$ = "left" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, lPic2.hDC, Tickz, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, lPic1.hDC, Tickz, 0, vbSrcPaint
End If
If Cmove$ = "right" Then
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, rPic2.hDC, Tickz, 0, vbSrcAnd
BitBlt Form1.hDC, Xpos, Ypos, cWidth, cHeight, rPic1.hDC, Tickz, 0, vbSrcPaint
End If
Frames = Frames + 1
End Sub
Private Sub Timer2_Timer()
Col = Col + 1
If Col = 4 Then
Col = 0
End If
If Col = 0 Then
Tickz = 0
End If
If Col = 1 Then
Tickz = 18
End If
If Col = 2 Then
Tickz = 36
End If
If Col = 3 Then
Tickz = 54
End If
End Sub
Private Sub Timer3_Timer()
' Print the Frame Rate and stuff.
Me.Caption = "Frame Rate : " & Frames
' Reset the Frame Rate.
Frames = 0
Label1.Caption = "X Position : " & " " & Xaxis & " " & "Y Position: " & " " & Yaxis
End Sub
this is my code for walking characters using biblt but i don't know how truely what it means my character blinks and try to analyze my code what's wrong ?