Пример #1
0
 public void clearParticles()
 {
     if (Particles != null)
     {
         Particles.Clear();
     }
     Particles = new List <Particle>();
 }
Пример #2
0
        public override void Explode(int qty = 100)
        {
            base.Explode();


            while (Busy)
            {
                ;
            }
            Busy = true;
            lock (Particles)
            {
                Particles.Clear();

                for (int i = 0; i < qty; i++)
                {
                    double angle = rng.NextDouble() * 2 * Math.PI;
                    double xVel  = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
                    double yVel  = (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);

                    Particles.Add(new Particle2D(Color,
                                                 (Vector2D)Position.Clone(),
                                                 new Vector2D(xVel, yVel)));
                    //Console.WriteLine("Added a particle, now there are " + Particles.Count);
                }
            }
            Busy = false;

            /*
             * Task.Factory.StartNew(() =>
             * {
             *  while (Busy) ;
             *  Busy = true;
             *  lock (Particles)
             *  {
             *      Particles.Clear();
             *
             *      for (int i = 0; i < qty; i++)
             *      {
             *          double angle = rng.NextDouble() * 2 * Math.PI;
             *          double xVel = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
             *          double yVel = (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);
             *
             *          Particles.Add(new Particle2D(Color,
             *              ((Vector2D)Position.Clone()),
             *              new Vector2D(xVel, yVel),
             *              ((Vector2D)Acceleration.Clone())));
             *          //Console.WriteLine("Added a particle, now there are " + Particles.Count);
             *      }
             *  }
             *  Busy = false;
             * });
             */
        }
Пример #3
0
        public override void Explode(int qty = 2000)
        {
            Task.Factory.StartNew(() =>
            {
                Exploded = true;

                while (Busy)
                {
                    ;
                }
                Busy = true;
                lock (Particles)
                {
                    List <Tuple <int, int> > coords = sprite.Coordinates;  // Can take a while the first time that it executes
                    qty = (int)(coords.Count * (rng.NextDouble() * 0.2 + 0.1));
                    Particles.Clear();

                    for (int i = 0; i < qty; i++)
                    {
                        // Gets coordinate out of the list of coordinates supplied by the sprite
                        Tuple <int, int> coord;
                        do
                        {
                            int randomT = rng.Next(0, (coords.Count > 0) ? coords.Count - 1 : 0);
                            coord       = coords[randomT];
                            if (coord == null)
                            {
                                coords.RemoveAt(randomT);
                            }
                        } while (coord == null);

                        double targetX = coord.Item1 * sprite.Zoom;
                        double targetY = ExplosionPlacementRadius *
                                         coord.Item2 * sprite.Zoom;


                        double angle = (targetX == 0) ? (targetY > 0) ? Math.PI / 2 : (targetY == 0) ? 0 : -1 * Math.PI / 2 :                         // Coordinate is on the Y-Axis
                                       (targetY == 0) ? (targetX < 0) ? Math.PI : 0 :                                                                 // coordinate is on the X-axis
                                       (targetY > 0) ? (targetX > 0) ? Math.Atan(targetY / targetX) : -1 * (Math.PI - Math.Atan(targetY / targetX)) : // Coordinate is above the X-axis
                                       (targetX > 0) ? Math.Atan(targetY / targetX) : -1 * (Math.PI - Math.Atan(targetY / targetX));                  // Coordinate is below the X-axis
                        double xVel = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
                        double yVel = -1 * (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);

                        Particles.Add(new Particle2D(Color,
                                                     new Vector2D(((Vector2D)Position).X + targetX, ((Vector2D)Position).Y - targetY),
                                                     new Vector2D(xVel, yVel)));
                    }
                }
                Busy = false;
            });
        }
Пример #4
0
        /// <summary>
        /// Start the particle system
        /// </summary>
        public void Start()
        {
            Particles.Clear(); // clear all the particles
            // Used to remove all forces that where Springs
            //List<Force> lForce = new List<Force>(Forces);
            //Forces = new ObservableCollection<Force>(lForce.FindAll(
            //    delegate(Force f) { return !f.GetType().Equals(typeof(Spring)); }));

            // for each emitter in the system generate particles
            foreach (Emitter emitter in Emitters)
            {
                emitter.GenerateParticles(this);
            }
            // start the system running
            mIsRunning = true; //mStopWatch.Start();
        }
Пример #5
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();
 }
Пример #6
0
        private void OnSceneEvent(Enums.SceneState state)
        {
            switch (state)
            {
            case Enums.SceneState.Playing:
                AddParticles(MaxParticles);
                break;

            case Enums.SceneState.Stopped:
            {
                Particles.Clear();

                CurrentPathLerpPosition = StartPathingLerpPosition;
                CurrentPathNodeIndex    = StartPathNodeIndex;
            }
            break;
            }
        }
        public void InitializeParticles()
        {
            Particles.Clear();

            TSPParticle firstParticle = TSPParticle.RandomGenerate(this, Map);

            Particles.Add(firstParticle);
            gBest = (TSPParticle)firstParticle.Clone();

            // Inicializar cada Partícula
            for (int pCount = 1; pCount < ParticleCount; ++pCount)
            {
                TSPParticle newParticle = TSPParticle.RandomGenerate(this, Map);
                Particles.Add(newParticle);
                if (newParticle.Fitness < gBest.Fitness)
                {
                    gBest = (TSPParticle)newParticle.Clone();
                }
            }
        }
Пример #8
0
        //------------------------------------------------------------------
        private void AddParticles()
        {
//            fraction.SetValue (1.0f);
            fraction.SetValue(4.0f);

            if (Debug.LeftMouse())
            {
                AddParticle(brush, Debug.Mouse());
            }

            foreach (var particle in Particles)
            {
                Batch.Begin(Sorting, blend, Sampling, null, null);
                //Color.Orange
                Batch.Draw(particle.Key, particle.Value, null, Color.White, 0.0f, Vector2.Zero, 1, SpriteEffects.None, 0.0f);
                Batch.End();
            }

            Particles.Clear();
        }
Пример #9
0
        /*
         * public virtual void ApplyForce(Vector2D force)
         * {
         *  Vector2D temp = force; /// Mass;
         *  Acceleration += temp;
         * }
         */

        /// <summary>
        /// Updates the firework by applying the gravity, and then determining if it needs to explode.
        /// </summary>
        public override void Update(int steps = 1)
        {
            if (!Exploded)
            {
                ApplyForce(PhysicsLib.Gravity2D);

                Velocity     += Acceleration;
                Position     += Velocity;
                Acceleration *= 0;

                if (((Vector2D)Velocity).Y >= 0)
                {
                    Explode();
                }
            }
            else
            {
                while (Busy)
                {
                    ;
                }
                Busy = true;
                lock (Particles)
                {
                    ExplosionAlpha -= ParticleDiminishRate;
                    foreach (AParticle p in Particles)
                    {
                        //Console.WriteLine(p);
                        p.ApplyForce(PhysicsLib.Gravity2D);
                        p.Velocity *= 0.95;
                        p.Update();
                    }
                    if (ExplosionAlpha <= 0)
                    {
                        Particles.Clear();
                    }
                }
                Busy = false;
            }
        }
Пример #10
0
        internal void ClearGame()
        {
            Projectiles.ForEach(p => p.WasCleared());
            Projectiles.Clear();

            Particles.ForEach(p => p.WasCleared());
            Particles.Clear();

            Collectables.ForEach(c => c.WasCleared());
            Collectables.Clear();

            Enemies.ForEach(e => e.WasCleared());
            Enemies.Clear();

            Map.ClearGame();

            EnemyDirector.ClearGame();

            MainPlayer.WasCleared();
            MainPlayer = null;

            MainCamera = null;
        }
Пример #11
0
 /// <summary>
 /// Removes all particles and animations.
 /// </summary>
 public void Clear()
 {
     Particles.Clear();
     Animations.Clear();
 }
Пример #12
0
 public void Clear()
 {
     Particles.Clear();
 }
Пример #13
0
 public void Reset()
 {
     lifeTimes.Clear();
     Particles.Clear();
 }