Time for action — creating the explosion

The method to emit explosion particles works in a similar way to the one that emits smoke.

  1. Insert a method called SpawnExplosion in the game class. The parameters are the x and y positions, and the amount of particles to create.
    Method SpawnExplosion:Int(x:Float, y:Float, amount:Int)
    
  2. Set the default layer to the game layer.
    eng.SetDefaultLayer(layerGame)
    
  3. Start a FOR loop for the local i variable ranging from 1 to the amount parameter of the method.
    For Local i:Int = 1 To amount
    
  4. Determine a random x offset that is used when an image object for the explosion particle is created.
    Local xoff:Float = Int(Rnd(0,3))
    
  5. Create a local object for the particle image. It will be placed at the coordinates given to the method.
    Local obj:=eng.CreateImage(atlas,144+xoff*16.0,80,16,16, x,y)
    
  6. Now, determine a random vector that will be 10 to 40 pixels and at a random angle around the given coordinates of the method.
    Local vec:Float[] = obj.GetVector(Rnd(10,40),Rnd(360))
    
  7. Create a position transition for the particle with the determined vector and a random duration of 1000 to 3000 milliseconds. The transition ID will be set to triDelete.
    Local trans:ftTrans = obj.CreateTransPos(vec[0], vec[1], Rnd(1000,3000), False, triDelete)
    
  8. Set the particle scale to a random factor of 0.1 to 1.0.
    obj.SetScale(Rnd(0.1,1.0))
    
  9. Add a scale transition with a random target scale ranging from 2.0 to 4.0.
    obj.AddTransScale(trans, Rnd(2.0,4.0), False)
    
  10. Lastly, add an alpha transition so it will fade out. The target alpha value is 0.5.
    obj.AddTransAlpha(trans, 0.5, False)
    
  11. Close the FOR loop and the method.
    Next
    Return 0
    End
    

What just happened?

You just created a method that can generate any explosion, no matter how big you want it to be. If you want more particle effects, then it might be a good idea to create a new layer and place these particles in it, so that they won't loop over during the collision detection phase.

Pow!—spawning a shot

We have smoke, we have explosions. But unless we add collision detection for the planes themselves, we will have nothing to hit the planes. We need bullets to be fired at your opponent.

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

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