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

  1. VERSION 5.00
  2. Object = "{5A65A9C0-089F-11D2-88AD-0000B45C4CF6}#1.2#0"; "EASYX.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3300
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4980
  9.    Icon            =   "Form1.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3300
  12.    ScaleWidth      =   4980
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin PROJECTEXLibCtl.EasyX EasyX 
  15.       Left            =   1200
  16.       OleObjectBlob   =   "Form1.frx":014A
  17.       Top             =   600
  18.    End
  19. Attribute VB_Name = "Form1"
  20. Attribute VB_GlobalNameSpace = False
  21. Attribute VB_Creatable = False
  22. Attribute VB_PredeclaredId = True
  23. Attribute VB_Exposed = False
  24. Option Explicit
  25. Dim SpriteArray(7) As Long
  26. Dim SurfaceOne As Long
  27. 'Spritearray constants
  28. Const SpriteRight As Long = 1
  29. Const SpriteLeft As Long = 0
  30. Const SpriteUp As Long = 5
  31. Const SpriteDown As Long = 4
  32. Const SpriteUpRight As Long = 6
  33. Const SpriteDownRight As Long = 7
  34. Const SpriteDownLeft As Long = 2
  35. Const SpriteUpLeft As Long = 3
  36. Const SpriteWidth As Long = 50
  37. Const SpriteHeight As Long = 50
  38. Const MovePrLoop As Long = 1
  39. Dim XDirection As Long
  40. Dim YDirection As Long
  41. Private Sub Form_Load()
  42. Dim rt As Long
  43. t forget this
  44. EasyX.Window = Me.hWnd
  45. ''''''''''''''''''''''
  46. 'Initialize direct draw
  47. rt = EasyX.InitDirectDraw(320, 200, 8)
  48. If rt <> EX_OK Then
  49.     EasyX.EndDirectX
  50.     MsgBox "Direct draw could not be initialized", vbOKOnly, "Failure"
  51.     Exit Sub
  52. End If
  53. 'initialize Direct input
  54. rt = EasyX.InitDirectInput
  55. If rt <> EX_OK Then
  56.     EasyX.EndDirectX
  57.     MsgBox "Direct input could not be initialized", vbOKOnly, "Failure"
  58.     Exit Sub
  59. End If
  60. 'Create the keyboard
  61. EasyX.CreateKeyboard
  62. 'Acquire the keyboard
  63. EasyX.AcquireKeyboard
  64. 'setup the the graphics
  65. SetGraphics
  66. RunMain
  67. End Sub
  68. Private Sub SetGraphics()
  69. Dim rt As Long
  70. Dim AppPath As String
  71. Dim I As Long, J As Long
  72. AppPath = App.Path & "\"
  73. XDirection = 1
  74. YDirection = 1
  75. 'load the graphics
  76. SurfaceOne = EasyX.LoadBitmapFile(AppPath & "arrows.bmp", 0)
  77. If SurfaceOne <> 0 Then
  78.     MsgBox "Could not load images", vbOKOnly, "Failure"
  79.     EasyX.EndDirectX
  80.     Exit Sub
  81. End If
  82. 'Define the sprites of the newly created surface
  83. For I = 1 To 2
  84.     For J = 1 To 4
  85.       SpriteArray(((I - 1) * 3) + J - 1) = _
  86.                                            EasyX.MakeSprite( _
  87.                                            (J - 1) * SpriteWidth, _
  88.                                            (I - 1) * SpriteHeight, _
  89.                                            J * SpriteWidth, _
  90.                                            I * SpriteHeight, SurfaceOne)
  91.     Next J
  92. Next I
  93. End Sub
  94. Private Sub RunMain()
  95. Static PointX As Long
  96. Static PointY As Long
  97. Dim Left As Long, Right As Long
  98. Dim Up As Long, Down As Long
  99. Static SpriteFrame As Long
  100.         
  101.         If EasyX.GetKeyState(EX_ESCAPE) = EX_KEYDOWN Then
  102.             EasyX.EndDirectX
  103.             Unload Me
  104.             Exit Do
  105.           
  106.         End If
  107.         
  108.         'Check the left & right keys
  109.         Left = EasyX.GetKeyState(EX_LEFT)
  110.         Right = EasyX.GetKeyState(EX_RIGHT)
  111.         If Left = EX_KEYDOWN Then
  112.         
  113.             PointX = PointX - MovePrLoop
  114.             SpriteFrame = SpriteLeft
  115.         End If
  116.         If Right = EX_KEYDOWN Then
  117.         
  118.             PointX = PointX + MovePrLoop
  119.             SpriteFrame = SpriteRight
  120.         End If
  121.         'Check up and down arrow keys
  122.         Up = EasyX.GetKeyState(EX_UP)
  123.         Down = EasyX.GetKeyState(EX_DOWN)
  124.         If Up = EX_KEYDOWN Then
  125.         
  126.             PointY = PointY - MovePrLoop
  127.             SpriteFrame = SpriteDown
  128.         
  129.         End If
  130.         If Down = EX_KEYDOWN Then
  131.         
  132.             PointY = PointY + MovePrLoop
  133.             SpriteFrame = SpriteUp
  134.            
  135.         End If
  136.     'Check for diagonal
  137.     If Down And Left = EX_KEYDOWN Then
  138.         SpriteFrame = SpriteDownLeft
  139.     ElseIf Down And Right = EX_KEYDOWN Then
  140.         SpriteFrame = SpriteDownRight
  141.     ElseIf Up And Left = EX_KEYDOWN Then
  142.         SpriteFrame = SpriteUpLeft
  143.     ElseIf Up And Right = EX_KEYDOWN Then
  144.         SpriteFrame = SpriteUpRight
  145.     End If
  146.     EasyX.FillSurface 0, EX_PRIMARYSURFACE
  147.     EasyX.DrawSprite PointX, PointY, SpriteWidth, SpriteHeight, SpriteFrame
  148.     EasyX.FlipSurface
  149.     DoEvents
  150. End Sub
  151.