Animation 21


‘5 picture boxs, 1 timer, 2 labels and 1 button

Option Explicit
Private 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
Const SRCCOPY = &HCC0020
Const SRCAND = &H8800C6
Const SRCPAINT = &HEE0086
Dim SpriteX& ‘ dim a long variable to hold the current X position on the Cave Dude sprite

Private Sub Command1_Click()

If Not Timer1.Enabled Then      ‘ jika timer mati
Timer1.Enabled = True       ‘ fungsi timer aktif
Command1.Caption = “Stop!”   ‘ tombol command berubah ->’STOP’
Else
Timer1.Enabled = False      ‘ jika timer hidup
Command1.Caption = “Go!”     ‘ tombol command berubah ->’Lanjut’
End If

End Sub

Private Sub Form_Load()

Dim ReturnResult& ‘dim a long variable to hold the return value BitBlt will pass
SpriteX& = 512 ‘ set the starting X coordinate for the Cave Dude sprite
ReturnResult& = BitBlt(picOldDisplay.hDC, 0, 0, 64, 64, picDisplay.hDC, SpriteX&, 64, SRCCOPY) ‘ copy a “clean” area from the display to be repainted when the loops comes around again to get rid of the old player X blit

End Sub

Private Sub Timer1_Timer()

Static AnimationCount& ‘ dim a long variable to hold which animation frame we are on, and make it static, so it retains its’ value between procedures
Dim ReturnResult& ‘dim a long variable to hold the return value BitBlt will pass

ReturnResult = BitBlt(picDisplay.hDC, SpriteX&, 64, 64, 64, picOldDisplay.hDC, 0, 0, SRCCOPY) ‘ copy the clean part of the display back over the old sprite X
SpriteX& = SpriteX& – 5 ‘the cave dude walks from right to left, so he starts out at a positive X location, and we decrement his location every loops by 5 pixels
ReturnResult = BitBlt(picOldDisplay.hDC, 0, 0, 64, 64, picDisplay.hDC, SpriteX&, 64, SRCCOPY) ‘ copy a “clean” area from the display to be repainted when the loops comes around again to get rid of the old player X blit
picOldDisplay.Refresh ‘ refresh the old display to reflect changes (this is only done to show what the contents of this picturebox look like. Normally this picturebox would not be visible to the player)
ReturnResult& = BitBlt(picWorkArea.hDC, 0, 0, 64, 64, picOldDisplay.hDC, 0, 0, SRCCOPY) ‘ copy the area the sprite will be blitted to into the work area
ReturnResult& = BitBlt(picWorkArea.hDC, 0, 0, 64, 64, picCaveDudeMask.hDC, AnimationCount&, 0, SRCAND) ‘ SRCAND the sprite mask on top of the display section we copied
ReturnResult& = BitBlt(picWorkArea.hDC, 0, 0, 64, 64, picCaveDude.hDC, AnimationCount&, 0, SRCPAINT) ‘ SRCPAINT the sprite on top of the mask and the display section
picWorkArea.Refresh ‘ refresh the work area to reflect changes(this is only done to show what the contents of this picturebox look like. Normally this picturebox would not be visible to the player)
ReturnResult& = BitBlt(picDisplay.hDC, SpriteX&, 64, 64, 64, picWorkArea.hDC, 0, 0, SRCCOPY) ‘ SRCCOPY the completed display section with transparent sprite back into the display picturebox
picDisplay.Refresh ‘ refresh the display to reflect the changes

If SpriteX& < -64 Then  ‘ if the Cave Dude walks off the screen completely, reset the program, and start him walking again
SpriteX& = 512
AnimationCount& = 0
picOldDisplay.Cls
picWorkArea.Cls
ReturnResult& = BitBlt(picOldDisplay.hDC, 0, 0, 64, 64, picDisplay.hDC, SpriteX&, 64, SRCCOPY) ‘ copy a “clean” area from the display to be repainted when the loops comes around again to get rid of the old player X blit
End If

AnimationCount& = AnimationCount& + 64 ‘ increment the animation by one frame

If AnimationCount& = 512 Then AnimationCount& = 0 ‘ if the AnimationCount is equal to the number of animation frames we have, reset the frame count to 0 to start over

End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s