November 25, 2020, 08:16:51 AM

Author Topic: [bb] Firework Effect by Xzider [ 1+ years ago ]  (Read 836 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Firework Effect by Xzider [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Firework Effect
Author : Xzider
Posted : 1+ years ago

Description : Short test with particles, kind of looks like fireworks, might help some one. You will need 2 images for the sparks, just name then Spark1.bmp and Spark2.bmp

Code :
Code: BlitzBasic
  1. Graphics3D 800,600,32,2
  2.  
  3. Global Temp_ParticleID%
  4. Global Dir%
  5. Global Camera% = CreateCamera()
  6.  
  7. Type Particle
  8.  
  9.   Field Entity%
  10.   Field TexName$
  11.   Field ID%
  12.   Field ParticleType%
  13.   Field X#
  14.   Field Y#
  15.   Field Z#
  16.   Field Scale0%
  17.   Field Scale1%
  18.   Field Alpha#
  19.   Field Counter0%
  20.   Field Counter1%
  21.   Field AlphaCounter0%
  22.   Field AlphaCounter1%
  23.   Field Color0%
  24.   Field Color1%
  25.   Field Color2%
  26.   Field Dir#
  27.   Field Dir1#
  28.   Field Dir2#
  29.   Field Dir3#
  30.   Field Gravity#
  31.  
  32. End Type
  33.  
  34. While Not KeyHit(1)
  35.  
  36.   If Rand(20) = 1
  37.  
  38.                 X# = Rand(-100,100)
  39.                 Y# = Rand(-100,100)
  40.                 Z# = Rand(100,250)
  41.                
  42.   For i=1 To 10
  43.  
  44.                 Create_Particle("Spark1.bmp",X#,Y#,Z#,1,1,1,1,255,255,255,1000)
  45.                 Create_Particle("Spark2.bmp",X#,Y#,Z#,1,1,1,1,255,255,255,1000)
  46.  
  47.   Next
  48.  
  49.   End If
  50.  
  51.  
  52.   Cls
  53.  
  54.   UpdateWorld
  55.   RenderWorld
  56.  
  57.                 Update_Particles()
  58.                
  59.   Flip
  60.  
  61. Wend
  62.  
  63.  
  64. Function Create_Particle(TempName$,TempX#,TempY#,TempZ#,TempAlpha#,TempType%,TempScale0%,TempScale1%,TempColor0%,TempColor1%,TempColor2%,TempCounter%)
  65.  
  66.                 Pa.Particle = New Particle
  67.                 PaTexName$ = TempName$
  68.                 PaX# = TempX#
  69.                 PaY# = TempY#
  70.                 Paz# = TempZ#
  71.                 PaAlpha# = TempAlpha#
  72.                 PaParticleType% = TempType%
  73.                 PaScale0% = TempScale0%
  74.                 PaScale1% = TempScale1%
  75.                 PaCounter0% = MilliSecs()
  76.                 PaCounter1% = TempCounter%
  77.                 PaAlphacounter0% = MilliSecs()
  78.                 PaAlphaCounter1% = 50
  79.                 PaColor0% = TempColor0%
  80.                 PaColor1% = TempColor1%
  81.                 PaColor2% = TempColor2%
  82.                 SeedRnd MilliSecs()
  83.                 PaDir1# = Rand(-1,1)
  84.                 PaDir2# = Rand(-1,1)
  85.                 PaDir3# = Rand(-1,1)
  86.                
  87.   If Dir% = 1
  88.  
  89.                 Dir% = 2
  90.                
  91.   Else
  92.  
  93.                 Dir% = 1
  94.                
  95.   End If
  96.  
  97.                 PaDir# = Dir%
  98.  
  99.                 PaEntity% = LoadSprite(PaTexName$)
  100.                 ScaleSprite PaEntity%,PaScale0%,PaScale1%
  101.                 EntityAlpha PaEntity%,PaAlpha#
  102.                 PositionEntity PaEntity%,PaX#,PaY#,Pa#
  103.                
  104.   If PaColor0% = 0 And PaColor1% = 0 And PaColor2% = 0
  105.  
  106.   Else
  107.  
  108.                 EntityColor PaEntity%,PaColor0%,PaColor1%,PaColor2%
  109.  
  110.   End If
  111.  
  112.   If Not PaEntity%
  113.  
  114.                 RuntimeError "Could not load sprite " + PaTexName$ + "!"
  115.                
  116.   End If
  117.  
  118. End Function
  119.  
  120. Function Update_Particles()
  121.  
  122.   For Pa.Particle = Each Particle
  123.  
  124. Select PaParticleType%
  125.  
  126.   Case 1
  127.  
  128.                 PaAlpha# = PaAlpha# - 0.01
  129.                
  130.                 EntityAlpha PaEntity%,PaAlpha#
  131.  
  132.                 MoveEntity PaEntity%,PaDir1#,PaDir2#,PaDir3#
  133.                 MoveEntity PaEntity%,0,PaGravity#,0
  134.                
  135.                 PaGravity# = PaGravity# - 0.05
  136.  
  137.   Default
  138.  
  139. End Select
  140.  
  141.   If MilliSecs() > PaAlphaCounter0% + PaAlphaCounter1% 
  142.  
  143.                 PaAlphaCounter0% = MilliSecs() 
  144.                
  145.   End If
  146.  
  147.   If MilliSecs() > PaCounter0% + PaCounter1% Or PaAlpha# <= 0
  148.  
  149.                 FreeEntity PaEntity%
  150.                 Delete Pa.Particle
  151.  
  152.   End If
  153.  
  154.   Next
  155.  
  156. End Function
  157.  
  158. Function DeleteParticles()
  159.  
  160.   For Pa.Particle = Each Particle
  161.  
  162.                 FreeEntity PaEntity%
  163.                 Delete Pa.Particle
  164.                
  165.   Next
  166.  
  167. End Function
  168.  
  169. Function New_ParticleID()
  170.  
  171.                 Temp_ParticleID% = Temp_ParticleID% + 1
  172.                
  173. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal