Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. Game #7, Air Dogs 1942 > Time for action — creating the explosion

Time for action — creating the explosion

Time for action — creating the explosion The method to emit explosion particles works in a similar way to the one that emits smoke. 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) Set the default layer to the game layer. eng.SetDefaultLayer(layerGame) 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 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)) 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) 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)) 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) Set the particle scale to a random factor of 0.1 to 1.0. obj.SetScale(Rnd(0.1,1.0)) 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) Lastly, add an alpha transition so it will fade out. The target alpha value is 0.5. obj.AddTransAlpha(trans, 0.5, False) 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.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint