Option Explicit
Private Type AnimationFrame
Top As Long
Left As Long
End Type
Dim DX As New DirectX7 'dEclare DX7 object, dont forget the 'new'
Dim DD As DirectDraw7
Dim PrimarySurface As DirectDrawSurface7 'The main surface user sEEs
Dim PrimeDesc As DDSURFACEDESC2
Dim OSPbackGround As DirectDrawSurface7 'OffscreenPlain background
Dim BackDesc As DDSURFACEDESC2
Dim OSPsprite As DirectDrawSurface7 'OffscreenpLain sprite
Dim SpriteDesc As DDSURFACEDESC2
Dim Clippa As DirectDrawClipper
Dim rPrime As RECT
Dim rBG As RECT
Dim rSprite As RECT
Dim Frame(3) As AnimationFrame
Dim curFrame As Long
Dim GoGoGo As Boolean
Dim ReturnValue As Long
Dim Temp As Long
Dim bBLT As Boolean 'tells whether to animaTe or not
Dim bINT As Boolean 'True if init is succesfuLL
Private Sub Form_Load()
Me.Height = 5000 'Set form height and width
Me.Width = 5000 'tHats the kid -_-
Init_DX_Stuff 'call this sub to set all variabLes/obj
Do While bBLT = True 'Loop while bBLT is true,
DoEvents
BitBlitter 'This is the main loop, that will animate
DoEvents
Loop
End Sub
Private Sub Init_DX_Stuff()
'DX objects-
Set DD = DX.DirectDrawCreate("")
Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
'Primary----
PrimeDesc.lFlags = DDSD_CAPS
PrimeDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set PrimarySurface = DD.CreateSurface(PrimeDesc)
'Background--
BackDesc.lFlags = DDSD_CAPS
BackDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Set OSPbackGround = DD.CreateSurfaceFromFile(App.Path & "\bg.bmp", BackDesc)
'Sprite------
SpriteDesc.lFlags = DDSD_CAPS
SpriteDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Set OSPsprite = DD.CreateSurfaceFromFile(App.Path & "\sprite.bmp", SpriteDesc)
'kLipper-----
Set Clippa = DD.CreateClipper(0)
Clippa.SetHWnd Me.hWnd
PrimarySurface.SetClipper Clippa
'CreateTable-
LookUpTable
'variabLes---
bINT = True
bBLT = True
GoGoGo = True
Form1.Show
End Sub
Private Sub BitBlitter()
'Check------
If bINT = False Then Exit Sub
'RectangLes-
Call DX.GetWindowRect(Me.hWnd, rPrime)
rSprite.Top = Frame(curFrame).Top
rSprite.Left = Frame(curFrame).Left
rSprite.Right = rSprite.Left + 36
rSprite.Bottom = rSprite.Top + 62
rBG.Bottom = BackDesc.lHeight
rBG.Right = BackDesc.lWidth
'rBG.Left = BackDesc.lWidth
'rBG.Top = BackDesc.lHeight
'AnimatioN
If DX.TickCount >= Temp + 1000 / 30 Then 'Check to see if Xmilliseconds passed or not
Temp = DX.TickCount
If GoGoGo = True Then
curFrame = curFrame + 1
If curFrame > UBound(Frame) Then
curFrame = UBound(Frame)
GoGoGo = False
End If
Else
curFrame = curFrame - 1
If curFrame < LBound(Frame) Then
curFrame = LBound(Frame)
GoGoGo = True
End If
End If
End If
'BlitterIt--
ReturnValue = OSPbackGround.BltFast(150, 150, OSPsprite, rSprite, DDBLTFAST_WAIT)
ReturnValue = PrimarySurface.Blt(rPrime, OSPbackGround, rBG, DDBLT_WAIT)
End Sub
Private Sub LookUpTable()
Frame(0).Left = 0
Frame(1).Left = 35
Frame(2).Left = 70
Frame(3).Left = 105
End Sub
Private Sub Form_Unload(Cancel As Integer)
bBLT = False
Unload Me
End Sub