home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch05 / sprite.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-24  |  8.2 KB  |  250 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSprite 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "The Sprite Program"
  5.    ClientHeight    =   5460
  6.    ClientLeft      =   1215
  7.    ClientTop       =   1530
  8.    ClientWidth     =   6075
  9.    Height          =   6150
  10.    Icon            =   "SPRITE.frx":0000
  11.    Left            =   1155
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   364
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   405
  17.    Top             =   900
  18.    Width           =   6195
  19.    Begin VB.Timer Timer1 
  20.       Interval        =   50
  21.       Left            =   2760
  22.       Top             =   720
  23.    End
  24.    Begin TegommLibCtl.Tegomm Tegomm1 
  25.       Height          =   495
  26.       Left            =   1320
  27.       TabIndex        =   0
  28.       Top             =   120
  29.       Width           =   3510
  30.       _version        =   65536
  31.       _extentx        =   6191
  32.       _extenty        =   873
  33.       _stockprops     =   64
  34.    End
  35.    Begin TegsprLibCtl.TegoSprite sprMan 
  36.       Left            =   2160
  37.       Top             =   2040
  38.       _version        =   65536
  39.       _extentx        =   1296
  40.       _extenty        =   1931
  41.       _stockprops     =   0
  42.       spritefilename  =   "C:\OCXPROG\PROGRAMS\CH05\MAN0.BMP"
  43.       maskfilename    =   "C:\OCXPROG\PROGRAMS\CH05\MMAN0.BMP"
  44.       spriteleft      =   144
  45.       spritetop       =   136
  46.       spriteheight    =   73
  47.       spritewidth     =   49
  48.    End
  49.    Begin TegsprLibCtl.TegoSprite sprBack 
  50.       Left            =   0
  51.       Top             =   0
  52.       _version        =   65536
  53.       _extentx        =   10716
  54.       _extenty        =   9710
  55.       _stockprops     =   0
  56.       spritefilename  =   "C:\OCXPROG\PROGRAMS\CH05\BGND.BMP"
  57.       maskfilename    =   "C:\OCXPROG\PROGRAMS\CH05\MBGND.BMP"
  58.       spriteheight    =   367
  59.       spritewidth     =   405
  60.       transparent     =   0   'False
  61.       autosize        =   -1  'True
  62.    End
  63.    Begin VB.Menu mnuFile 
  64.       Caption         =   "&File"
  65.       Begin VB.Menu mnuExit 
  66.          Caption         =   "E&xit"
  67.       End
  68.    End
  69.    Begin VB.Menu mnuHelp 
  70.       Caption         =   "&Help"
  71.       Begin VB.Menu mnuAbout 
  72.          Caption         =   "&About..."
  73.       End
  74.    End
  75. Attribute VB_Name = "frmSprite"
  76. Attribute VB_Creatable = False
  77. Attribute VB_Exposed = False
  78. ' All variables must be declared.
  79. Option Explicit
  80. ' Declare handles for the show's sprites.
  81. Dim gBack As Long
  82. Dim gMan0 As Long
  83. Dim gMan1 As Long
  84. Dim gMan2 As Long
  85. Dim gMan3 As Long
  86. Private Sub Form_Load()
  87.   Dim Path
  88.   ' Get the name of the directory where the
  89.   ' program resides.
  90.   Path = App.Path
  91.   If Right(Path, 1) <> "\" Then
  92.      Path = Path + "\"
  93.   End If
  94.   ' Open a WAV file for background music.
  95.   Tegomm1.Visible = False
  96.   Tegomm1.DeviceType = "WaveAudio"
  97.   Tegomm1.filename = Path + "LASTC2M6.WAV"
  98.   Tegomm1.Command = "Open"
  99.   ' Start playing the WAV file.
  100.   Tegomm1.Command = "Play"
  101.   ' Initialize all the sprite controls.
  102.   sprBack.InitializeSprite Me.hWnd
  103.   sprMan.InitializeSprite Me.hWnd
  104.       
  105.   ' Open all the sprites that will be used in our show.
  106.   gMan0 = sprBack.OpenSprite(Path + "man0.bmp")
  107.   gMan1 = sprBack.OpenSprite(Path + "man1.bmp")
  108.   gMan2 = sprBack.OpenSprite(Path + "man2.bmp")
  109.   gMan3 = sprBack.OpenSprite(Path + "man3.bmp")
  110.   gBack = sprBack.OpenSprite(Path + "bgnd.bmp")
  111. End Sub
  112. Private Sub Form_Paint()
  113.    ' Draw the sprBack sprite inside WinG
  114.    sprBack.SpriteHandle = gBack
  115.    sprBack.DrawSprite
  116.    ' Draw the sprMan sprite inside WinG.
  117.    sprMan.SpriteHandle = gMan0
  118.    sprMan.DrawSprite
  119.    ' Slam WinG into the screen
  120.    sprBack.SlamIt
  121. End Sub
  122. Private Sub Form_Unload(Cancel As Integer)
  123.    ' Free all the sprites of the show.
  124.    sprBack.CloseSprite (gBack)
  125.    sprBack.CloseSprite (gMan0)
  126.    sprBack.CloseSprite (gMan1)
  127.    sprBack.CloseSprite (gMan2)
  128.    sprBack.CloseSprite (gMan3)
  129. End Sub
  130. Private Sub mnuAbout_Click()
  131.    Dim Title
  132.    Dim Msg
  133.    Dim CR
  134.    CR = Chr(13) + Chr(10)
  135.    ' Prepare the title of the About message box.
  136.    Title = "About the Sprite Program"
  137.    Msg = "This program was written with Visual "
  138.    Msg = Msg + "Basic for Windows, using the "
  139.    Msg = Msg + "TegoSoft Sprite OCX control. "
  140.    Msg = Msg + CR + CR
  141.    Msg = Msg + "The TegoSoft Sprite OCX control "
  142.    Msg = Msg + "is part of the TegoSoft OCX Control "
  143.    Msg = Msg + "Kit - a collection of various OCX controls. "
  144.    Msg = Msg + CR + CR
  145.    Msg = Msg + "For more information about the "
  146.    Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  147.    Msg = Msg + "at:"
  148.    Msg = Msg + CR + CR
  149.    Msg = Msg + "TegoSoft Inc." + CR
  150.    Msg = Msg + "P.O. Box 389" + CR
  151.    Msg = Msg + "Bellmore, NY 11710"
  152.    Msg = Msg + CR + CR
  153.    Msg = Msg + "Phone: (516)783-4824"
  154.    ' Display the About message box.
  155.    MsgBox Msg, vbInformation, Title
  156.    ' Make sure that there is playback after
  157.    ' the user closes the modal message box.
  158.    Tegomm1.Command = "Play"
  159. End Sub
  160. Private Sub mnuExit_Click()
  161.    ' Terminate the program.
  162.    Unload Me
  163. End Sub
  164. Private Sub Tegomm1_Done()
  165.    ' If playback reached the end of the WAV file,
  166.    ' rewind the WAV file and play again.
  167.    If Tegomm1.Position = Tegomm1.Length Then
  168.       Tegomm1.Command = "Prev"
  169.       Tegomm1.Command = "Play"
  170.    End If
  171. End Sub
  172. Private Sub Timer1_Timer()
  173.    Static WalkingDirection
  174.    Dim ManLeft, ManTop, ManWidth, ManHeight
  175.    ' If the program's window is currently minimized,
  176.    ' exit this procedure.
  177.    If Me.WindowState = 1 Then
  178.       Exit Sub
  179.    End If
  180.    ' Draw the section of the background where the
  181.    ' Man sprite is located.
  182.    ManLeft = sprMan.SpriteLeft
  183.    ManTop = sprMan.SpriteTop
  184.    ManWidth = sprMan.SpriteWidth
  185.    ManHeight = sprMan.SpriteHeight
  186.    sprBack.SpriteHandle = gBack
  187.    sprBack.PartialDraw ManLeft, ManTop, ManWidth, ManHeight
  188.                        
  189.    ' The following If-ElseIf statements, animate
  190.    ' the sprMan sprite control. The man is moving
  191.    ' inside a room in four directions:
  192.    ' Direction 0 - Towards the user next to the left
  193.    '               wall of the room.
  194.    ' Direction 1 - From the left side of the room to
  195.    '               the right side of the room.
  196.    ' Direction 2 - Away from the user next to the
  197.    '               right wall of the room.
  198.    ' Direction 3 - From the right side of the room
  199.    '               to the left side of the room.
  200.    '   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  201.    '   x     <-----------------------     x
  202.    '   x  |         Direction 3           x
  203.    '   x  |                           /|\ x
  204.    '   x  |                            |  x
  205.    '   x  |Direction          Direction|  x
  206.    '   x  |   0                   2    |  x
  207.    '   x  |                            |  x
  208.    '   x  |                            |  x
  209.    '   x \|/        Direction 1           x
  210.    '   x     ------------------------->   x
  211.    '   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  212.    If WalkingDirection = 0 Then
  213.       ' Show the man going in direction 0.
  214.       sprMan.StretchBottom 10
  215.       sprMan.StretchLeft 5
  216.       sprMan.SpriteHandle = gMan0
  217.       sprMan.DrawSprite
  218.       If sprMan.SpriteHeight >= 210 Then
  219.          WalkingDirection = 1
  220.       End If
  221.    ElseIf WalkingDirection = 1 Then
  222.       ' Show the man going in direction 1.
  223.       sprMan.SpriteLeft = sprMan.SpriteLeft + 6
  224.       sprMan.SpriteHandle = gMan1
  225.       sprMan.DrawSprite
  226.       If sprMan.SpriteLeft >= 220 Then
  227.          WalkingDirection = 2
  228.       End If
  229.    ElseIf WalkingDirection = 2 Then
  230.       ' Show the man going in direction 2.
  231.       sprMan.StretchBottom -10
  232.       sprMan.StretchRight -5
  233.       sprMan.SpriteHandle = gMan2
  234.       sprMan.DrawSprite
  235.       If sprMan.SpriteHeight <= 80 Then
  236.          WalkingDirection = 3
  237.       End If
  238.    ElseIf WalkingDirection = 3 Then
  239.       ' Show the man going in direction 3.
  240.       sprMan.SpriteLeft = sprMan.SpriteLeft - 6
  241.       sprMan.SpriteHandle = gMan3
  242.       sprMan.DrawSprite
  243.       If sprMan.SpriteLeft <= 150 Then
  244.          WalkingDirection = 0
  245.       End If
  246.    End If
  247.    ' Slam WinG into the screen.
  248.    sprBack.SlamIt
  249. End Sub
  250.