home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / easyx / data1.cab / Example_Files / EX_1 / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-03  |  4.1 KB  |  135 lines

  1. VERSION 5.00
  2. Object = "{5A65A9C0-089F-11D2-88AD-0000B45C4CF6}#1.2#0"; "EASYX.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Animation Demo"
  5.    ClientHeight    =   2595
  6.    ClientLeft      =   165
  7.    ClientTop       =   450
  8.    ClientWidth     =   4680
  9.    Icon            =   "Form1.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   173
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   312
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin PROJECTEXLibCtl.EasyX EasyX 
  16.       Left            =   960
  17.       OleObjectBlob   =   "Form1.frx":014A
  18.       Top             =   120
  19.    End
  20. Attribute VB_Name = "Form1"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26. Dim SurfaceOne As Long      'The sprite surface
  27. Dim SpriteArray(11) As Long 'The sprite array
  28. Dim X As Integer
  29. Dim Y As Integer
  30. Const ScreenWidth As Long = 800
  31. Const ScreenHeight As Long = 600
  32. Const MovePrLoop As Long = 10
  33. Const SpriteHeight As Long = 25
  34. Const SpriteWidth As Long = 25
  35. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  36. Private Declare Function GetTickCount Lib "kernel32" () As Long
  37. Private Sub SetUp()
  38. Dim rt As Long
  39. Dim AppPath As String
  40. Dim I As Integer, J As Integer
  41. AppPath = App.Path & "\"
  42. '....Always remember this....
  43. EasyX.Window = Me.hWnd     '.
  44. '............................
  45. 'Initialize
  46. rt = EasyX.InitDirectDraw(ScreenWidth, ScreenHeight, 8)
  47. If rt <> EX_OK Then
  48.     MsgBox "Direct draw initialization failed", vbOKOnly, "Direct draw failed"
  49.     Exit Sub
  50. End If
  51. SurfaceOne = EasyX.LoadBitmapFile(AppPath & "balls.bmp", 0)
  52. 'The surface is the first surface to load so it must be 0
  53. 'See the documentation on loading bitmaps
  54. If SurfaceOne <> 0 Then
  55.     EasyX.EndDirectX    'End the session
  56.     'Notify user
  57.     MsgBox "The bitmap file could not be loaded", vbOKOnly, "Bitmap load failed"
  58. End If
  59. 'get the keyboard
  60. EasyX.InitDirectInput
  61. EasyX.CreateKeyboard
  62. EasyX.CreateKeyboard
  63. 'Fill the back (which will be the primary, when flipped) surface with black
  64. EasyX.FillSurface 0, EX_PRIMARYSURFACE
  65. 'Define the sprites of the newly created surface
  66. For I = 1 To 3
  67.     For J = 1 To 4
  68.       SpriteArray(((I - 1) * 3) + J - 1) = _
  69.                                            EasyX.MakeSprite( _
  70.                                            (J - 1) * SpriteWidth, _
  71.                                            (I - 1) * SpriteHeight, _
  72.                                            J * SpriteWidth, _
  73.                                            I * SpriteHeight, SurfaceOne)
  74.     Next J
  75. Next I
  76. X = 1
  77. Y = 1
  78. RunMain
  79. End Sub
  80. Private Sub Form_Load()
  81. SetUp
  82. End Sub
  83. Private Sub RunMain()
  84. Dim CurrentTick As Long
  85. Dim LastTick As Long
  86. Const TickDifference As Long = 5
  87.     EasyX.AcquireKeyboard
  88.     If EasyX.GetKeyState(EX_ESCAPE) = EX_KEYDOWN Then
  89.         EasyX.EndDirectX
  90.         Unload Me
  91.         Exit Do
  92.     End If
  93.       
  94.       CurrentTick = GetTickCount()
  95.        
  96.     If CurrentTick - LastTick > TickDifference Then
  97.         LastTick = CurrentTick
  98.         Update
  99.         DoEvents
  100.     Else
  101.                  
  102.         DoEvents
  103.         Sleep 1
  104.         
  105.     End If
  106.          
  107.         
  108. End Sub
  109. Private Sub Update()
  110. Static AnimationSeq As Integer
  111. Static PointX As Integer, PointY As Integer
  112.            
  113.                
  114. 'Update movement
  115. If PointX < 0 Or PointX > (ScreenWidth - SpriteWidth) Then
  116.     X = X * -1
  117. End If
  118. If PointY < 0 Or PointY > (ScreenHeight - SpriteHeight) Then
  119.     Y = Y * -1
  120. End If
  121. PointX = PointX + (X * MovePrLoop)
  122. PointY = PointY + (Y * MovePrLoop)
  123. 'Fill the surface with a given palette index
  124. EasyX.FillSurface 0, EX_PRIMARYSURFACE
  125. 'Draw the sprite
  126. EasyX.DrawSprite PointX, PointY, SpriteWidth, SpriteHeight, AnimationSeq
  127. EasyX.FlipSurface
  128. 'Update the sprite animation sequence
  129. AnimationSeq = AnimationSeq + 1
  130. 'reset the sequence if the variable is out of the array bound
  131. If AnimationSeq > UBound(SpriteArray) Then
  132.     AnimationSeq = 0
  133. End If
  134. End Sub
  135.