home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / spritest.bas < prev    next >
Encoding:
BASIC Source File  |  1998-01-22  |  6.6 KB  |  207 lines

  1. Attribute VB_Name = "SpriteStuff"
  2. Global Const PALLETE_RED = 1
  3. Global Const PALLETE_GREEN = 2
  4. Global Const PALLETE_BLUE = 3
  5. Global Const PALLETE_WHITE = 4
  6. Global Const PALLETE_YELLOW = 5
  7. Global Const PALLETE_SKYBLUE = 6
  8.  
  9. Global Const NOSPRITE = -999
  10.  
  11. Global Const MAXPICZ = 200
  12. Global Const MAXLIBS = 100
  13. Private Type GrphxLib
  14.   Active As Boolean
  15.   LibName As String
  16.   Width As Integer
  17.   Height As Integer
  18.   HalfWidth As Integer
  19.   HalfHeight As Integer
  20. End Type
  21. Global GraphicsLibs(MAXLIBS) As GrphxLib
  22. Type SpriteDefType
  23.   SpriteNumber As Integer
  24.   SpriteGroupNumber As Integer
  25.   SpriteFrameNumber As Integer
  26.   SpriteFrameTicks As Integer
  27. End Type
  28. Private Type Pcz
  29.   Active As Boolean
  30.   GraphicsLib As Integer
  31.   SourceRect As RECT
  32.   Width As Integer
  33.   Height As Integer
  34.   HalfWidth As Integer
  35.   HalfHeight As Integer
  36.   PicName As String
  37. End Type
  38. Global Pics(MAXPICZ) As Pcz
  39. Private Type Frme
  40.   PicNum As Integer
  41.   FrameDuration As Integer
  42.   FrameName As String
  43. End Type
  44. Global Const MAXSPRITEFRAMES = 10
  45. Private Type SpriteGrps
  46.   GroupName As String
  47.   Frames(1 To MAXSPRITEFRAMES) As Frme
  48.   FrameMax As Integer
  49.   RepeatSequence As Boolean
  50. End Type
  51. Global Const MAXSPRITEGROUPS = 10
  52. Private Type Spritez
  53.   Active As Boolean
  54.   SpriteName As String
  55.   SpriteGroups(0 To MAXSPRITEGROUPS) As SpriteGrps
  56.   SpriteGroupMax As Integer
  57. End Type
  58. Global Const MAXSPRITES = 100
  59. Global Sprites(0 To MAXSPRITES) As Spritez
  60. Global SpriteMax As Integer
  61. Public Function GetSpriteIndex(SpriteName$) As Integer
  62. GetSpriteIndex = -999
  63. For I = 1 To MAXSPRITES
  64.   If Sprites(I).Active = True Then
  65.     If Sprites(I).SpriteName = SpriteName$ Then
  66.       GetSpriteIndex = I
  67.       Exit For
  68.     End If
  69.   End If
  70. Next I
  71. End Function
  72. Public Function GetPicIndex(PName)
  73. GetPicIndex = -1
  74. For I = 1 To MAXPICZ
  75.   If Pics(I).Active = True Then
  76.     If Pics(I).PicName = PName Then
  77.       GetPicIndex = I
  78.       Exit For
  79.     End If
  80.   End If
  81. Next I
  82. End Function
  83. Public Function GetGraphicsLibIndex(PName)
  84. GetGraphicsLibIndex = -1
  85. For I = 1 To MAXLIBS
  86.   If GraphicsLibs(I).Active = True Then
  87.     If GraphicsLibs(I).LibName = PName Then
  88.       GetGraphicsLibIndex = I
  89.       Exit For
  90.     End If
  91.   End If
  92. Next I
  93. End Function
  94. Public Sub LoadSpriteData()
  95. SpriteMax = 0
  96. For I = 1 To MAXSPRITES
  97.   Sprites(I).Active = False
  98. Next I
  99. Call FileFunctions.OpenGameFile(File_SpriteDefinitions, 1)
  100. Do
  101.   Line Input #1, a$
  102.   propvalue$ = MiscFunctions.GetPropertyValue(a$)
  103.   Select Case MiscFunctions.GetPropertyName(a$)
  104.   Case FILETAG_ENDFILE
  105.     Exit Do
  106.   Case "[SPRITEDEF]"
  107.     SpriteMax = SpriteMax + 1
  108.     Sprites(SpriteMax).SpriteGroupMax = 0
  109.     Sprites(SpriteMax).Active = True
  110.     Line Input #1, a$
  111.     Sprites(SpriteMax).SpriteName = GetPropertyValue(a$)
  112.     Do
  113.       Line Input #1, a$
  114.       Select Case MiscFunctions.GetPropertyName(a$)
  115.       Case "[ENDSPRITEDEF]"
  116.         Exit Do
  117.       Case "-FRAMEGROUP-"
  118.         Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax = 0
  119.         Sprites(SpriteMax).SpriteGroupMax = Sprites(SpriteMax).SpriteGroupMax + 1
  120.         Line Input #1, a$
  121.         Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).GroupName = GetPropertyValue(a$)
  122.         Line Input #1, a$
  123.         Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).RepeatSequence = ConvertTrueFalse(a$)
  124.         Do
  125.           Line Input #1, a$
  126.           Select Case MiscFunctions.GetPropertyName(a$)
  127.           Case "-ENDFRAMEGROUP-"
  128.             Exit Do
  129.           Case "-FRAME-"
  130.             Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax = Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax + 1
  131.             Line Input #1, a$
  132.             Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).Frames(Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax).FrameName = GetPropertyValue(a$)
  133.             Line Input #1, a$
  134.             Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).Frames(Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax).FrameDuration = Val(GetPropertyValue(a$))
  135.             Line Input #1, a$
  136.             Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).Frames(Sprites(SpriteMax).SpriteGroups(Sprites(SpriteMax).SpriteGroupMax).FrameMax).PicNum = SpriteStuff.GetPicIndex(GetPropertyValue(a$))
  137.           End Select
  138.         Loop
  139.       End Select
  140.     Loop
  141.   End Select
  142. Loop
  143. Close #1
  144. End Sub
  145. Public Sub LoadPictureData()
  146. 'Loads all the picture definitions for the game
  147. 'like the X and Ys of them.
  148. Libnum = 0
  149. Call FileFunctions.OpenGameFile(File_PictureDefinitions, 3)
  150.   Do
  151.     Line Input #3, a$
  152.     Select Case a$
  153.     Case FILETAG_ENDFILE
  154.       Exit Do
  155.     Case "[PICDEF]"
  156.       PicNum = PicNum + 1
  157.       Pics(PicNum).Active = True
  158.       Line Input #3, a$
  159.       Pics(PicNum).PicName = MiscFunctions.GetPropertyValue(a$)
  160.       Line Input #3, a$
  161.       Pics(PicNum).GraphicsLib = GetGraphicsLibIndex(MiscFunctions.GetPropertyValue(a$))
  162.       Line Input #3, a$
  163.       Pics(PicNum).SourceRect.Left = Val(MiscFunctions.GetPropertyValue(a$))
  164.       Line Input #3, a$
  165.       Pics(PicNum).SourceRect.Top = Val(MiscFunctions.GetPropertyValue(a$))
  166.       Line Input #3, a$
  167.       Pics(PicNum).Width = Val(MiscFunctions.GetPropertyValue(a$))
  168.       Pics(PicNum).HalfWidth = Int(Pics(PicNum).Width / 2)
  169.       Pics(PicNum).SourceRect.Right = Pics(PicNum).SourceRect.Left + Pics(PicNum).Width
  170.       Line Input #3, a$
  171.       Pics(PicNum).Height = Val(MiscFunctions.GetPropertyValue(a$))
  172.       Pics(PicNum).HalfHeight = Int(Pics(PicNum).Height / 2)
  173.       Pics(PicNum).SourceRect.bottom = Pics(PicNum).SourceRect.Top + Pics(PicNum).Height
  174.     End Select
  175.   Loop
  176. Close #3
  177. End Sub
  178. Public Sub LoadGraphicLibData()
  179. 'Loads all the picture files for the game
  180. Libnum = 0
  181. Call FileFunctions.OpenGameFile(File_GraphicLibDefinitions, 3)
  182.   Do
  183.     Line Input #3, a$
  184.     Select Case a$
  185.     Case FILETAG_ENDFILE
  186.       Exit Do
  187.     Case "[GRAPHICSLIBRARYDEF]"
  188.       Libnum = Libnum + 1
  189.       GraphicsLibs(Libnum).Active = True
  190.       Line Input #3, a$
  191.       GraphicsLibs(Libnum).LibName = MiscFunctions.GetPropertyValue(a$)
  192.       Line Input #3, a$
  193.       Filename = MiscFunctions.GetPropertyValue(a$)
  194.       Call GraphicsEngine.LoadGraphic(Libnum, Directory_GameData & Directory_Graphics & Filename)
  195.     End Select
  196.   Loop
  197. Close #3
  198. End Sub
  199. Public Sub UnloadGraphicLibraries()
  200. For I = 1 To MAXLIBS
  201.   If GraphicsLibs(I).Active = True Then
  202.     GraphicsLibs(I).Active = False
  203.     Set GraphicSurfaces(I) = Nothing
  204.   End If
  205. Next I
  206. End Sub
  207.