Example #1
0
        private void UpdateParticles()
        {
            foreach (Particle o in DeadParticles)
            {
                o.Die(this);
                Particles.Remove(o);
            }
            DeadParticles.Clear();

            foreach (Particle o in NewParticles)
            {
                Particles.Add(o);
            }
            NewParticles.Clear();
        }
Example #2
0
 // Crap, when must this happen?
 // It can happen whenever Objs is the current state... which is thoretically always.
 // This will nuke the particles though.
 // This is actually pretty close to correct.
 public void SetLevel(int level)
 {
     UpdateObjects();
     Objs.Remove(Player);
     Levels[CurrentLevel].Objs = Objs;
     // This is PROBABLY right, but I'm not sure.
     CurrentLevel = level;
     Objs         = Levels[CurrentLevel].Objs;
     Objs.Add(Player);
     NewObjs.Clear();
     DeadObjs.Clear();
     Particles.Clear();
     NewParticles.Clear();
     DeadParticles.Clear();
     UpdateCollisionTree();
 }
Example #3
0
        public void Update(float frameTime)
        {
            foreach (var particle in LiveParticles)
            {
                particle.Update(frameTime);
            }
            //Parallel.ForEach(LiveParticles, particle => particle.Update(frameTime));

            if (!Emit)
            {
                return;
            }
            _particlesToEmit += frameTime * EmitRate;
            var newParticleCount = (int)Math.Floor(_particlesToEmit);

            //This should go down to zero.
            _particlesToEmit -= newParticleCount;

            //Clear out last update
            _newParticles.Clear();

            //Take some dead particles
            _newParticles.AddRange(DeadParticles.Take(newParticleCount));

            newParticleCount -= _newParticles.Count();

            //If there aren't enough dead ones, take the remainder from the live ones, oldest first.
            if (newParticleCount > 0)
            {
                _newParticles.AddRange(LiveParticles.Take(newParticleCount));
            }

            for (var i = 0; i < _newParticles.Count(); i++)
            {
                EmitParticle(_newParticles[i]);
            }
        }
Example #4
0
 public void KillParticle(Particle p)
 {
     DeadParticles.Add(p);
 }