home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / ASPRITE.ZIP / tutorial.fr_ / tutorial.fr (.txt)
Encoding:
Visual Basic Form  |  1998-05-01  |  4.1 KB  |  112 lines

  1. VERSION 5.00
  2. Object = "{8661C691-76E8-11D1-AE63-0004ACFF9AE2}#1.0#0"; "ASPRITE.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   2445
  6.    ClientLeft      =   615
  7.    ClientTop       =   795
  8.    ClientWidth     =   3750
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   2445
  11.    ScaleWidth      =   3750
  12.    Begin ASPRITELib.ASprite ASprite1 
  13.       Height          =   732
  14.       Left            =   1320
  15.       TabIndex        =   0
  16.       Top             =   600
  17.       Width           =   1212
  18.       _Version        =   65536
  19.       _ExtentX        =   2138
  20.       _ExtentY        =   1291
  21.       _StockProps     =   0
  22.    End
  23. Attribute VB_Name = "Form1"
  24. Attribute VB_GlobalNameSpace = False
  25. Attribute VB_Creatable = False
  26. Attribute VB_PredeclaredId = True
  27. Attribute VB_Exposed = False
  28. Option Explicit
  29. '**********
  30. '** This example application uses the ASprite ActiveX Control
  31. '** For more ASprite examples, visit
  32. '**           http://www.dreamscape.com/beaulieu
  33. '** This code and the ASprite ActiveX Control are furnished
  34. '** without warranty of any kind. The author cannot be held
  35. '** liable for any damages due to their use.
  36. '**********
  37. '** This example shows a minimal DirectX app with keyboard
  38. '** and joystick input, buffered sound, and sprite collision.
  39. '**********
  40. Const DIRECTION_STOPPED = 0
  41. 'ShowCursor used to hide hourglass that VB puts up when busy
  42. Private Declare Function ShowCursor Lib "User32" (ByVal bShow As Integer) As Integer
  43. Private Sub Form_Activate()
  44.     Dim xx As Integer
  45.     'make sure we're in the dir with all of the bmps and wavs
  46.     ChDir App.Path
  47.     'notify DirectX of our main window
  48.     ASprite1.hWnd = Form1.hWnd
  49.     'initialize DirectSound
  50.     ASprite1.SoundInit
  51.     'load our two wav sound files
  52.     ASprite1.SoundLoad 0, "explode.wav"
  53.     ASprite1.SoundLoad 1, "laugh.wav"
  54.     'initialize DirectDraw
  55.     ASprite1.DrawInit 640, 480, 8, 0
  56.     'load tutorial.bmp - it will contain 16 sprites, and will use
  57.     'palette entry 11 (blue) for transparent color
  58.     ASprite1.SpriteLoad "tutorial.bmp", 16, 11
  59.     'define sprite 0
  60.     ASprite1.SpriteDefine 0, 290, 215, 0, 0, 80, 65, 16, 8, 1, 1
  61.     'define sprites 1 thru 15
  62.     For xx = 1 To 15
  63.         ASprite1.SpriteDefine xx, Int((600 * Rnd) + 1), Int((440 * Rnd) + 1), 0, 130, 78, 79, 8, 8, Int((8 * Rnd) + 1), 1
  64.     Next
  65.     'set our text window attributes
  66.     ASprite1.TextSetAttributes 639, 60, "Arial", 32, RGB(255, 255, 0), RGB(0, 0, 0)
  67.     'turn control over to the rendering loop
  68.     RunMain
  69. End Sub
  70. Public Sub RunMain()
  71.     Dim iCurrentDirection, xx As Integer
  72.     Dim bContinue As Boolean
  73.     bContinue = True
  74.     ShowCursor (False)
  75.     Do While bContinue
  76.         If ASprite1.InputIsKeyPressed(vbKeyEscape) Then
  77.             'User wants to quit!
  78.             bContinue = False
  79.         End If
  80.         ' read the user input - try keyboard first the joystick
  81.         iCurrentDirection = ASprite1.InputKeyArrowDirection
  82.         If iCurrentDirection = DIRECTION_STOPPED Then
  83.             iCurrentDirection = ASprite1.InputJoyStickDirection
  84.         End If
  85.         'fill the back buffer with palette entry 0 (black)
  86.         ASprite1.DrawFloodFill 0
  87.         'move and display sprite 0 (ball)
  88.         ASprite1.SpriteMove 0, iCurrentDirection, 4
  89.         ASprite1.SpriteSetNextFrame 0
  90.         ASprite1.SpriteDisplay 0
  91.         'animate and display sprites 1 thru 16 (faces)
  92.         For xx = 1 To 16
  93.             ASprite1.SpriteSetNextFrame xx
  94.             ASprite1.SpriteDisplay xx
  95.             If ASprite1.SpriteGetActive(xx) And Int((800 * Rnd) + 1) = 1 Then
  96.                 ASprite1.SoundPlay 1
  97.             End If
  98.             If ASprite1.SpriteTestCollision(0, xx) Then
  99.                 ASprite1.SpriteSetActive xx, False
  100.                 ASprite1.SoundPlay 0
  101.             End If
  102.         Next
  103.         ASprite1.TextDisplay "ASprite ActiveX Control Tutorial", 1, 420
  104.         ASprite1.DrawFlipBackBuffer
  105.     Loop
  106.     ShowCursor (True)
  107.     ' clean up and get out
  108.     ASprite1.DrawDisable
  109.     ASprite1.SoundDisable
  110.     Unload Form1
  111. End Sub
  112.