📜 ⬆️ ⬇️

Particles System in crowd modeling (3)

We continue the conversation of 04/10/2014 ( Particles System in crowd modeling (2) ).

In this part:
  1. add the death of the shooter (because the explosions are killing)
  2. play around with the settings of the emitters - I want epic


add the death of the shooter (because the explosions are killing)
')
In order to "kill the arrow", there are many different ways. I will choose the most common - to reduce a certain "amount of health" to zero or less. But in order to reduce anything, it is necessary to first provide it with health ( HealthInitializer ).
During particle initialization, with the help of HealthInitializer , a new user variable “health” is added to the properties of the Particle.dictionary class .

package waylines.initializers { import org.flintparticles.common.particles.Particle; import org.flintparticles.common.emitters.Emitter; import org.flintparticles.common.initializers.InitializerBase; public class HealthInitializer extends InitializerBase { private var health:int; public function HealthInitializer(health:int=100) { this.health = health; } override public function initialize( emitter : Emitter, particle : Particle ) : void { particle.dictionary["health"] = health; } } } 


Particles got health, and now you can reduce it.
Changes to the main code:

 override protected function setup(e:Event=null):void { super.setup(e); //  " "   -  emitterWaylines.addInitializer( new HealthInitializer(100)); } 

 /* *   (     -     ) * 1.   explosion ""   emitterWaylines     emitterExplosion * 2.          . *   ,  ""    * -     ,      */ override protected function explosion(e:MouseEvent):void { /* *     -     emitterWaylines */ super.explosion(e); /* *  copy-paste   * ,          */ ... var particles:Array = emitterExplosion.particlesArray; var length:int = particles.length; for(var r:int=0; r<length; r++) { ... if(Point.distance(explPoint, particlePoint) < explRadius) { particleClone = Particle2D(particles[r]); particleClone.angVelocity = -5 + Math.random() * 10; /* *  " "   " " -    ... */ particleClone.lifetime += 1; //particleClone.age = 0; /* *       ( 10  40 ) */ particleClone.dictionary["health"] -= (10 + Math.random() * 30); } } } 


Everything is working. It is not clear who hurt and who killed. You can add color differentiation pants pants .
Insert a couple of lines into MainWaylines_3.explosion () :

 /* *        -    ,    */ if(particle.dictionary["health"] <= 0) { //  "" -   addBlot(particle); //   particle.isDead = true; } else { //  "" -   Arrow(particle.image).color = getArrayColorByHealth(particle.dictionary["health"]); } 


play around with the settings of the emitters - I want epic

The particle library , taken as the basis for working on an application, operates with physical laws (mass, gravity ...) - subtle matter, for me in any case (not techie). Yes, and surely it would take to write your own add-ons - which is highly undesirable (I want to play with programming like with purchased children's dice, rather than sharpening myself on a lathe).
Therefore:


 override protected function setup(e:Event=null):void { super.setup(e); //  " "   -  emitterWaylines.addInitializer( new HealthInitializer(100)); /* * " "    (  ) * - - .1 */ emitterWaylines.maximumFrameTime = .001; emitterWaylinesForMonsterArrows.maximumFrameTime = .001; /* * -      ,   ,    * (,        -        ,    ) */ emitterWaylines.addAction( new Antigravities(emitterWaylinesForMonsterArrows, -4000000) );//  400000 emitterWaylines.addAction( new MinimumDistance( 7, 6000 ) );//  600 } 


The potential enemy as a result began to move much slower - in proportion to its size relative to the map (if it’s goblins or zombies, for example). The map itself can be scaled, the coordinates of the particles extrapolated to larger (smaller) screens.



Well, actually, this is what I wanted to share - the principle of crowd modeling using the Particle System. The result is an almost finished prototype Model (MVC) for Tower Defense. Of course, 60 fps, with such a particle density, cannot be achieved ... But - there is much to optimize (in the previous parts I have mentioned), to fasten a free render (Starling, Away3d)

The code is available on google code . Class MainWaylines_3

PS: there will be time, I will definitely show a bolted render

Source: https://habr.com/ru/post/221197/


All Articles