Time for action — emitting the smoke

The method we have created to spawn smoke will be called once a plane gets hit. The more hits it takes, the higher the chance of emitting a smoke particle.

  1. Create a new method called SpawnSmoke inside the game class. The parameters are the plane object and the number of hits.
    Method SpawnSmoke:Int(plane:ftObject, hits:Int)
    
  2. Check whether a random number ranging from 0 to 100 will be greater than 100-hits times 10.
    If Rnd(0,100)>(100-hits*10) Then
    
  3. If yes, set the default layer to layerGame.
    eng.SetDefaultLayer(layerGame)
    
  4. Determine a vector that is located in the back of the plane. The distance is 20 pixels and the angle is calculated randomly taking the hits into account.
    Local vec:Float[] = plane.GetVector(20,180+Rnd(-10*hits,10*hits),True)
    
  5. Randomly determine an x offset for the next CreateImage call from the sprite atlas. This is used to choose the smoke images randomly.
    Local xoff:Float = Int(Rnd(0,3))
    
  6. Create a local image object that reassembles the smoke particle.
    Local obj := eng.CreateImage(atlas,144+xoff*16.0,64,16,16, vec[0],vec[1])
    

    The smoke particles won't move, but the change in their alpha value over time means they will fade out.

  7. Now, create an alpha transition to an alpha value of 0.1, at a random time between 1000 and 3000 milliseconds. The transition ID will be triDelete.
    Local trans:ftTrans = obj.CreateTransAlpha(0.1, Rnd(1000, 3000), False, triDelete)
    
  8. Set the particle scale randomly from a factor of 0.1 to 0.5.
    obj.SetScale(Rnd(0.1,0.5))
    
  9. Add a scale transition for a random scale of 1.0 to 4.0.
    obj.AddTransScale(trans, Rnd(1.0,4.0), False)
    
  10. Close this method.
    Return 0
    End
    

What just happened?

You created a method that will let you emit smoke particles behind a plane, depending on how many hits that plane took.

Boom!—Emitting explosions

What comes after smoke? Sometimes, it's a big explosion. If a plane takes too many hits, it will explode.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.233.41