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

  1. Attribute VB_Name = "VisualEffects"
  2. Private Type Anims
  3.   Active As Boolean
  4.   Position As Point3D
  5.   SpriteNum As Integer
  6.   CurrentFrame As Integer
  7. End Type
  8. Global Const MaxAnims = 200
  9. Global Animations(MaxAnims) As Anims
  10. Global AnimsActive As Integer
  11. Type Spark
  12.   Position As Point3D
  13.   Health As Integer
  14.   Active As Boolean
  15.   Pallete As Integer
  16.   Yaw As Integer
  17.   Speedup As Single
  18.   Speed As Single
  19.   Decay As Integer
  20.   Weight As Integer
  21. End Type
  22. Global Const MaxSparks = 500
  23. Global Sparks(MaxSparks) As Spark
  24. Global SparksActive As Integer
  25. Type Sparkler
  26.   Position As Point3D
  27.   Health As Integer
  28.   Active As Boolean
  29.   Pallete As Integer
  30.   Yaw As Integer
  31.   Speedup As Single
  32.   Speed As Single
  33.   Decay As Integer
  34.   Weight As Single
  35. End Type
  36. Global Const MaxSparkles = 500
  37. Global Sparkles(MaxSparkles) As Sparkler
  38. Global SparklesActive As Integer
  39. Type Fire
  40.   Position As Point3D
  41.   Health As Integer
  42.   Active As Boolean
  43.   Size As Integer
  44.   Decay As Integer
  45. End Type
  46. Global Const MaxFires = 500
  47. Global Fires(MaxFires) As Fire
  48. Global FiresActive As Integer
  49. Type AnimSpewer
  50.   Position As Point3D
  51.   Health As Integer
  52.   Active As Boolean
  53.   Size As Integer
  54.   SpriteNum As Integer
  55. End Type
  56. Global Const MaxAnimSpewers = 500
  57. Global AnimSpewers(MaxAnimSpewers) As AnimSpewer
  58. Global AnimSpewersActive As Integer
  59. Public Sub SpawnAnimationSpewer(X, Y, SpriteNum, Size, Duration)
  60. For I = 1 To MaxAnimSpewers
  61.   If AnimSpewers(I).Active = False Then
  62.     CurrAnimSpewer = I
  63.     Exit For
  64.   End If
  65. Next I
  66. With AnimSpewers(CurrAnimSpewer)
  67.   .Active = True
  68.   .Position.X = X
  69.   .Position.Y = Y
  70.   .Position.Z = 0
  71.   .Health = Duration
  72.   .Size = Size
  73.   .SpriteNum = SpriteNum
  74. End With
  75. If AnimSpewersActive < CurrAnimSpewer Then AnimSpewersActive = CurrAnimSpewer
  76. End Sub
  77. Public Sub RunVisualEffects()
  78. Call RunFires
  79. Call RunSparks
  80. Call RunSparkles
  81. Call RunAnimations
  82. Call RunAnimationSpewers
  83. End Sub
  84. Public Sub RunAnimationSpewers()
  85. For I = 1 To AnimSpewersActive
  86.   If AnimSpewers(I).Active = True Then
  87.     With AnimSpewers(I)
  88.       .Health = .Health - 1
  89.       If .Health < 1 Then .Active = False
  90.       If Int(2 * Rnd) = 1 Then
  91.         Call SpawnAnimation(.Position.X + Int((.Size * Rnd) - (.Size / 2)), .Position.Y + Int((.Size * Rnd) - (.Size / 2)), .SpriteNum)
  92.       End If
  93.     End With
  94.   End If
  95. Next I
  96. End Sub
  97. Public Sub RunFires()
  98. For I = 1 To FiresActive
  99.   If Fires(I).Active = True Then
  100.     With Fires(I)
  101.       .Health = .Health - .Decay
  102.       If .Health < 1 Then .Active = False
  103.       For I2 = 1 To .Size
  104.         Call SpawnSpark(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, 360 * Rnd, 1.5, 35, 4, 0)
  105.       Next I2
  106.     End With
  107.   End If
  108. Next I
  109. End Sub
  110. Public Sub SpawnFire(X, Y, Z, Size, Decay)
  111. For I = 1 To MaxFires
  112.   If Fires(I).Active = False Then
  113.     CurrFire = I
  114.     Exit For
  115.   End If
  116. Next I
  117. With Fires(CurrFire)
  118.   .Active = True
  119.   .Position.X = X
  120.   .Position.Y = Y
  121.   .Position.Z = Z
  122.   .Health = 100
  123.   .Decay = Decay
  124.   .Size = Size
  125. End With
  126. If FiresActive < CurrFire Then FiresActive = CurrFire
  127. End Sub
  128. Public Sub SpawnSparkleExplosion(X, Y, Z, Pallete, Number)
  129. For I = 1 To Number
  130.   Call SpawnSparkle(X, Y, Z, Pallete, Int(360 * Rnd), 3, 20, 3, 1)
  131. Next I
  132. End Sub
  133. Public Sub SpawnSparkle(X, Y, Z, Pallete, Yaw, SpeedMax, Decay, Speedup, Weight)
  134. For I = 1 To MaxSparkles
  135.   If Sparkles(I).Active = False Then
  136.     CurrSparkle = I
  137.     Exit For
  138.   End If
  139. Next I
  140. With Sparkles(CurrSparkle)
  141.   .Active = True
  142.   .Speedup = (Speedup * Rnd) + 3
  143.   .Position.X = X
  144.   .Position.Y = Y
  145.   .Position.Z = Z
  146.   .Yaw = Yaw
  147.   .Health = 255
  148.   .Pallete = Pallete
  149.   .Speed = (SpeedMax * Rnd) + 1
  150.   .Decay = Decay
  151.   .Weight = Weight
  152. End With
  153. If SparklesActive < CurrSparkle Then SparklesActive = CurrSparkle
  154. End Sub
  155.  
  156. Public Sub SpawnSparkExplosion(X, Y, Z, Pallete, Size, Intensity)
  157. For I = 1 To Intensity
  158.   Call SpawnSpark(X, Y, Z, Pallete, Int(360 * Rnd), Size, 20, 6, 1)
  159. Next I
  160. End Sub
  161. Public Sub SpawnSparkDirectionalExplosion(X, Y, Z, Pallete, Size, Intensity, Direction)
  162. For I = 1 To Intensity
  163.   Call SpawnSpark(X, Y, Z, Pallete, CheckYaw(Direction + (Int(140 * Rnd) - 80)), Size, 20, 4, 1)
  164. Next I
  165. End Sub
  166. Public Sub SpawnSpark(X, Y, Z, Pallete, Yaw, SpeedMax, Decay, Speedup, Weight)
  167. For I = 1 To MaxSparks
  168.   If Sparks(I).Active = False Then
  169.     CurrSpark = I
  170.     Exit For
  171.   End If
  172. Next I
  173. With Sparks(CurrSpark)
  174.   .Active = True
  175.   .Speedup = (Speedup * Rnd) + 0.3
  176.   .Position.X = X
  177.   .Position.Y = Y
  178.   .Position.Z = Z
  179.   .Yaw = Yaw
  180.   .Health = 255
  181.   .Pallete = Pallete
  182.   .Speed = SpeedMax * Rnd + 0.01
  183.   .Decay = Decay
  184.   .Weight = Weight
  185. End With
  186. If SparksActive < CurrSpark Then SparksActive = CurrSpark
  187. End Sub
  188. Public Sub RunSparkles()
  189. For I = 1 To SparklesActive
  190.   With Sparkles(I)
  191.     If .Active = True Then
  192.       .Health = .Health - .Decay
  193.       .Position = Math.GetPropelCoordinates(.Position, .Yaw, 0, .Speed)
  194.       .Position.Z = .Position.Z + .Speedup
  195.       .Speedup = .Speedup - .Weight
  196.       Call SpawnSpark(.Position.X, .Position.Y, .Position.Z, .Pallete, 360 * Rnd, 1, 50, 0, 0.5)
  197.       If .Position.Z < 0 Then
  198.         .Position.Z = 0
  199.         .Speed = .Speed / 1.2
  200.       End If
  201.       If .Health < 1 Then
  202.         .Active = False
  203.         For I2 = 1 To SparklesActive
  204.           If Sparkles(I2).Active = True Then
  205.             SparklesNum = I2
  206.           End If
  207.         Next I2
  208.         SparklesActive = SparklesNum
  209.       End If
  210.     End If
  211.   End With
  212. Next I
  213. End Sub
  214.  
  215. Public Sub RunSparks()
  216. For I = 1 To SparksActive
  217.   With Sparks(I)
  218.     If .Active = True Then
  219.       .Health = .Health - .Decay
  220.       .Position = Math.GetPropelCoordinates(.Position, .Yaw, 0, .Speed)
  221.       .Position.Z = .Position.Z + .Speedup
  222.       .Speedup = .Speedup - .Weight
  223.       If .Position.Z < 0 Then
  224.         .Position.Z = 0
  225.         .Speed = .Speed / 1.2
  226.       End If
  227.       If .Health < 1 Then
  228.         .Active = False
  229.         For I2 = 1 To SparksActive
  230.           If Sparks(I2).Active = True Then
  231.             SparksNum = I2
  232.           End If
  233.         Next I2
  234.         SparksActive = SparksNum
  235.       End If
  236.     End If
  237.   End With
  238. Next I
  239. End Sub
  240. Public Sub RunAnimations()
  241. For I = 1 To AnimsActive
  242.   With Animations(I)
  243.     If .Active = True Then
  244.       .CurrentFrame = .CurrentFrame + 1
  245.       If .CurrentFrame > Sprites(.SpriteNum).SpriteGroups(1).FrameMax Then
  246.         .Active = False
  247.         For I2 = 1 To AnimsActive
  248.           If Animations(I2).Active = True Then
  249.             AnimNum = I2
  250.           End If
  251.         Next I2
  252.         AnimsActive = AnimNum
  253.       End If
  254.     End If
  255.   End With
  256. Next I
  257. End Sub
  258. Public Sub SpawnAnimation(X, Y, SpriteNum)
  259. For I = 1 To MaxAnims
  260.   If Animations(I).Active = False Then
  261.     CurrAnim = I
  262.     Exit For
  263.   End If
  264. Next I
  265. With Animations(CurrAnim)
  266.   .Active = True
  267.   .Position.X = X
  268.   .Position.Y = Y
  269.   .SpriteNum = SpriteNum
  270.   .CurrentFrame = 1
  271. End With
  272. If AnimsActive < CurrAnim Then AnimsActive = CurrAnim
  273. End Sub
  274. Public Sub Effect_RailgunTrail(SourcePoint As Point3D, DestinationPoint As Point3D)
  275. Dim DrawPoint As Point3D
  276. Const StepDistance = 2
  277. Yaw = Math.GetYawFromPoints(SourcePoint, DestinationPoint)
  278. DrawPoint = SourcePoint
  279. For I = 1 To Math.GetDistance(SourcePoint, DestinationPoint) / StepDistance
  280.   DrawPoint.X = DrawPoint.X + (SinTable(Yaw) * StepDistance)
  281.   DrawPoint.Y = DrawPoint.Y + (CosTable(Yaw) * StepDistance)
  282.   TrailRotation = TrailRotation + 60
  283.   If TrailRotation > 360 Then TrailRotation = TrailRotation - 360
  284.   XOffset = SinTable(TrailRotation)
  285.   YOffset = CosTable(TrailRotation)
  286.   If Int(2 * Rnd) = 1 Then Call SpawnSpark(DrawPoint.X, DrawPoint.Y, 4, PALLETE_RED, Int(360 * Rnd), 0.1, 15, 0, 0)
  287.   Call SpawnSpark(DrawPoint.X + XOffset, DrawPoint.Y + YOffset, 5, PALLETE_SKYBLUE, TrailRotation, 0.3, 15, 0, 0)
  288. Next I
  289. End Sub
  290.