//*********************************************************************************
//                          SPARK Wrapper Fire Demo
//                              Advanced Fire
//*********************************************************************************



sync on
sync rate 0


// load the campfire scene

load object "media\firecamp\firecamp.x",1


color backdrop rgb(10,10,15)


hide light 0

load image "media\explosion.bmp",1
load image "media\fire2.bmp",2



// create the fire system
fireSystem = sp create system (0,0,0.55,0)

// create 2 Groups , one for the fire and one for the smoke

fireGroup = sp add group (fireSystem , 235 , 0.65 , 0,0,0)
smokeGroup = sp add group (fireSystem , 335 , 0.65 , 0,0,0)

// set they lifetime

sp set group lifetime fireGroup,1,1.5
sp set group lifetime smokeGroup,5,5

fireRenderer = sp set quad renderer (fireGroup ,1 , 0.3,0.3,2,2,BLEND_ADD)

// We want to create a relistic fire effect so we will add 5 emitters !

fireEmitter1 = sp add straight emitter(fireGroup , 0,1,0,25,1,2.5,-1 , sp sphere zone(0,-1,0 ,0.5))
fireEmitter2 = sp add straight emitter(fireGroup ,1,0.6,0,12,0.5,1.5, -1,sp sphere zone(0.15,-1.2,0.075,0.1))
fireEmitter3 = sp add straight emitter(fireGroup ,-0.6,0.12,-0.8,8,0.5,1.5, -1,sp sphere zone(-0.375,-1.15,-0.375,0.3))
fireEmitter4 = sp add straight emitter(fireGroup ,-0.8,0.5,0.2,15,0.5,1.5, -1,sp sphere zone(-0.255,-1.2,0.225,0.2))
fireEmitter5 = sp add straight emitter(fireGroup ,0.1,0.8,-1.0,15,0.5,1.5, -1,sp sphere zone(-0.075,-1.2,-0.3,0.2))


interp2 = sp add interpolator (fireGroup ,PARAM_ANGLE, 0 ,2 ,0,2 )
interp3 = sp add interpolator (fireGroup ,PARAM_ATLAS_DIMENSIONS, 0,4 , 1 )

// the scale parameter will use a graph interpolator

fireGraph = sp add param graph (fireGroup , PARAM_SCALE)
sp add param graph entry fireGraph , 0.5 , 2 , 5
sp add param graph entry fireGraph , 1 , 0 ,0

// we set a random interpolator for color

colorInterpolator = sp add rgba interpolator (fireGroup , sp rgba(204,128,77,20) , sp rgba(230,153,50,40) , sp rgba(204,128,77,0) , sp rgba(230,153,50,0))
 

// ********************* now we setup the smoke group *********************

smokeRenderer = sp set quad renderer (smokeGroup ,1 , 0.3,0.3,2,2,BLEND_ADD)


interp = sp add interpolator (smokeGroup , PARAM_SCALE , 5 , 10 , 1)
interp = sp add interpolator (smokeGroup , PARAM_ANGLE , 0 , 2 , 0,2)
interp = sp add interpolator (smokeGroup , PARAM_ATLAS_DIMENSIONS , 0 , 4 , 1)

// set a graph interpolator for the color

colorGraph = sp add rgba graph (smokeGroup)
sp add rgba graph entry colorGraph , 0 , sp rgba(43,28,28,2)
sp add rgba graph entry colorGraph , 0.2 , sp rgba(28,28,28,55)
sp add rgba graph entry colorGraph , 1 , sp rgba(20,20,20,0)

//our smoke group will have only 1 emitter

smokeEmitter = sp add spheric emitter (smokeGroup , 0.0,1.0,0.0,0.1,2.5 * 3.14 , 25 , 0.5,1,-1, sp sphere zone (0,0,0,1.2))

// and now we set gravity modifiers to our groups

gr1 = sp add gravity modifier (fireGroup ,0,7.5,0)
gr2 = sp add gravity modifier (smokeGroup ,0,1.3,0)


// alternatively you can save this system and when you need 
// a fire system in the scene just load the file , position it and thats all

// sp save system "FireEffect.spk", fireSystem

movespeed# = -8


do
    
    
  if upkey() = 1 then movespeed# = movespeed#+0.1
   if downkey() = 1 then movespeed# = movespeed#-0.1
  

   position camera 0,0,0,0 
   rotate camera 0 , camera angle X(0)+ mousemovey()*0.25 , camera angle y(0)+ mousemovex()*0.25 , 0
   move camera 0,movespeed#
   sync
   sp update
  
    
    loop
    












