Particles... Particles

Miscellaneous Forums/Blitz Showcase/Particles... Particles

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.



That said, just stick this in an include or something and call the appropriate functions (there're only two, and they're fairly self explanatory).

;Explosions for the Lotus particle system.
;Media from the lps_test2.zip archive is required.
;InitExplosion()  -  Call this to initialize the required emitters.
;Explode(X,Y,Z)  -  Call this to create an explosion at X,Y,Z

;I'm still working on projectile explosions >:)

Global gExpSmoke,gExpSmokeTrail,gExpSpark,gExpFire

Function InitExplosion()
     Local Fire,Smoke,SparkMesh,SparkTex

     ;; Load textures.  And stuff.
     Fire = LoadTexture("fire.png",1+16+32)
     Smoke = LoadTexture("smoke.png",1+2+16+32)
     SparkMesh = LoadMesh("beam.3ds")
     RotateMesh SparkMesh,90,0,0
     ScaleMesh SparkMesh,.2,.2,.2
     HideEntity SparkMesh ;woops, forgot that
     SparkTex = LoadTexture("beam.png",1+16+32)

     If Not Fire Or Smoke Or SparkMesh Or SparkTex Then RuntimeError "Uh-oh!  Explosion couldn't be created due to one or more of the four intial variables being 0!  Papa had an oopsie!"

     gExpFire = CreateEmitter(Fire)
          SetEmitterLifeSpan gExpFire,50
          SetEmitterSizeFrom gExpFire,4,4,4
          SetEmitterSizeTo gExpFire,6.7,6.7,6.7
          SetEmitterColorFrom gExpFire,0,0,0,2
          SetEmitterColorTo gExpFire,255,255,255,0
          SetEmitterBlend gExpFire,3
          SetEmitterVelocity gExpFire,0,0,.025


     gExpSmoke = CreateEmitter(Smoke)
          SetEmitterLifeSpan gExpSmoke,96
          SetEmitterSizeFrom gExpSmoke,5,5,5
          SetEmitterSizeTo gExpSmoke,10,10,10
          SetEmitterColorFrom gExpSmoke,0,0,0,2
          SetEmitterColorTo gExpSmoke,192,192,192,0
          SetEmitterBlend gExpSmoke,3


     gExpSmokeTrail = CopyEmitter(gExpSmoke)
          SetEmitterLifeSpan gExpSmokeTrail,32
          SetEmitterSizeFrom gExpSmokeTrail,.5,.5,.5
          SetEmitterSizeTo gExpSmokeTrail,1.3,1.3,1.3
          SetEmitterWaitSpan gExpSmokeTrail,5
          SetEmitterAngle gExpSmokeTrail,-90,0,0
          SetEmitterAcceleration gExpSmokeTrail,0,0,.001


     gExpSpark = CreateEmitter(SparkTex)
          SetEmitterLifeSpan gExpSpark,40
          SetEmitterVelocity gExpSpark,0,0,.15
          SetEmitterAcceleration gExpSpark,0,0,.005
          SetEmitterAngleAcceleration gExpSpark,.04,0,0
          SetEmitterParticleMesh gExpSpark,SparkMesh
          SetEmitterSizeFrom gExpSpark,.9,.9,.3
          SetEmitterSizeTo gExpSpark,.3,.3,.9   ;reverse!
          SetEmitterViewMode gExpSpark,2
          SetEmitterColorFrom gExpSpark,255,228,209,1
          SetEmitterColorTo gExpSpark,255,138,0,0
          SetEmitterBlend gExpSpark,3
          SetEmitterTrail gExpSpark,gExpSmokeTrail

     Return True
End Function


Function Explode(X#,Y#,Z#)
     If Not gExpFire Or gExpSmoke Or gExpSmokeTrail Or gExpSpark Then RuntimeError "Explosion emitters not initialized"
     For N = 0 To 5
          Angle = Rand(359)
          Off = Rnd(-2,2)
          SetEmitterPosition gExpFire,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpFire,Angle,Angle,Angle
          CreateParticle gExpFire
     Next

     For N = 0 To 5
          Angle = Rand(359)
          SetEmitterPosition gExpSmoke,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpFire,Angle,Angle,Angle
          CreateParticle gExpSmoke
     Next

     For N = 0 To 7
          SetEmitterPosition gExpSpark,X+Rnd(-2,2),Y+Rnd(-2,2),Z+Rnd(-2,2)
          SetEmitterAngle gExpSpark,Rand(-80,10),Rand(359),45
          CreateParticle gExpSpark
     Next
     Return True
End Function