TGC Codebase Backup



Fire Effect by Hamish McHaggis

24th Dec 2003 6:53
Summary

A nice camp fire/torch/whatever fire effect using particles.



Description

This is basically my previous smoke code (search 'smoke' on the codebase) edited. Loads of different effects can be gotten from this method.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Fire particle effect (edited from smoke particle effect)
`By Joseph Thomson
`24/12/03

`Setup
sync on
sync rate 40
hide mouse

`Number of fire particles
numFireParticles=50

`Particle value arrays
dim fireParticlesPos#(numFireParticles,3)
dim fireParticlesVel#(numFireParticles,3)
dim fireParticlesSize#(numFireParticles,3)
dim fireParticlesFade#(numFireParticles,2)

`Create fire image
create bitmap 1,50,50
ink rgb(200,130,30),0
`Draw random dots in a circle shape
for x=1 to 1000
   ang=rnd(360)
   rad=rnd(20)
   dot 25+sin(ang)*rad,25+cos(ang)*rad
next x
`Blur fire image
blur bitmap 1,3
get image 1,0,0,50,50
delete bitmap 1

backdrop on
color backdrop rgb(0,0,0)

`Make particles
for x=1 to numFireParticles
   make object plain x,10,10
   texture object x,1
   hide object x
   `Deactivate ambient light
   set object ambient x,0
   `Make black areas see through
   set object transparency x,1
   `Ghost particle
   ghost object on x
next x

position camera 0,20,-50

do
   `Position new particle at origin every nth time
   inc count
   if count=1 then count=0
   if count=0
      `Increase number of particle to reset
      inc currentParticle
      `Loop round if you reach the end of the particles
      if currentParticle>numFireParticles then currentParticle=1
      `Reset particle values
      `Position
      fireParticlesPos#(currentParticle,1)=rnd(4)-2
      fireParticlesPos#(currentParticle,2)=rnd(2)
      fireParticlesPos#(currentParticle,3)=rnd(4)-2
      `Scale
      fireParticlesSize#(currentParticle,1)=100
      fireParticlesSize#(currentParticle,2)=100
      `Velocity (randomize)
      fireParticlesVel#(currentParticle,1)=rnd(100)/1000.0-0.05
      fireParticlesVel#(currentParticle,2)=rnd(100)/1000.0+0.5
      fireParticlesVel#(currentParticle,3)=rnd(100)/1000.0-0.05
      fireParticlesFade#(currentParticle,1)=200
      `Show the particle
      show object currentParticle
   endif

   `Loop through particles
   for x=1 to numFireParticles
      `Re-position and scale particle values
      for y=1 to 3
         fireParticlesSize#(x,y)=fireParticlesSize#(x,y)-2.0
         fireParticlesPos#(x,y)=fireParticlesPos#(x,y)+fireParticlesVel#(x,y)
      next y
      `Fade particle value
      fireParticlesFade#(x,1)=fireParticlesFade#(x,1)-3.0
      `Position, scale and fade particle object
      position object x,fireParticlesPos#(x,1),fireParticlesPos#(x,2),fireParticlesPos#(x,3)
      scale object x,fireParticlesSize#(x,1),fireParticlesSize#(x,2),100
      fade object x,fireParticlesFade#(x,1)
      `Point at camera
      set object to camera orientation x
   next x
   sync
loop