/// <summary>
        /// Constructs a new particle emitter object.
        /// </summary>
        public ParticleEmitter(ParticleSystem particleSystem,
            float particlesPerSecond, Vector3 initialPosition)
        {
            this.particleSystem = particleSystem;

            timeBetweenParticles =  1.0f / particlesPerSecond;

            previousPosition = initialPosition;
        }
        public void Draw(SpriteBatch sb, ParticleSystem ps)
        {
            foreach (var p in ps.Particles) {
                if (p != null) {
                    var c = Color;
                    c.A = (byte)MathHelper.Lerp(255, 0, (p.Age / (float)p.MaxAge));
                    var p0 = p.Position.ToVector2() * scale + Position;
                    sb.Draw(texture, p0, null, c, 0, origin, 1f, SpriteEffects.None, 0f);
                }
            }

            foreach (var a in ps.Attractors) {
                var pos = a.Position.ToVector2() * scale + Position;
                sb.Draw(texture, pos, null, Color, 0, origin, 1f, SpriteEffects.None, 0f);
            }
        }
Example #3
0
        /// <summary>
        /// Constructs a new projectile.
        /// </summary>
        public Projectile(ParticleSystem explosionParticles,
            ParticleSystem explosionSmokeParticles,
            ParticleSystem projectileTrailParticles)
        {
            this.explosionParticles = explosionParticles;
            this.explosionSmokeParticles = explosionSmokeParticles;

            // Start at the origin, firing in a random (but roughly upward) direction.
            position = Vector3.Zero;

            velocity.X = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange;
            velocity.Y = (float)(random.NextDouble() + 0.5) * verticalVelocityRange;
            velocity.Z = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange;

            // Use the particle emitter helper to output our trail particles.
            trailEmitter = new ParticleEmitter(projectileTrailParticles,
                                               trailParticlesPerSecond, position);
        }
 public ParticleSystemVisualizer(ParticleSystem ps, Vector2 position, float scale)
 {
     particleSystem = ps;
     Position = position;
     this.scale = scale;
 }
Example #5
0
 /// <summary>
 /// removes the passed in ParticleSystem from the internal list once 
 /// it is stopped and has no active particles, this will destroy the
 /// particle system and its particles if no other references to it exists
 /// </summary>
 /// <param name="ps">ParticleSystem to destroy</param>
 public static void DestroyIdlePS(ParticleSystem ps)
 {
     if (!ps.isPlaying && ps.particleCount == 0)
         DestroyActivePS(ps);
     else if (!destroySystems.Contains(ps))
         destroySystems.Add(ps);
 }
Example #6
0
 /// <summary>
 /// removes the passed in ParticleSystem from the internal list, this will destroy 
 /// the particle system and its particles if no other references to it exists
 /// </summary>
 /// <param name="ps">ParticleSystem to destroy</param>
 public static void DestroyActivePS(ParticleSystem ps)
 {
     if (ps != null && particleSystems.Contains(ps))
         particleSystems.Remove(ps);
 }
Example #7
0
        /// <summary>
        /// creates a new ParticleSystem using the passed in Texture2D and returns it
        /// (use the returned ParticleSystem to change the particle system settings)
        /// </summary>
        /// <param name="texture">texture that each of this ParticleSystem's particles will use</param>
        /// <returns>ParticleSystem</returns>
        public static ParticleSystem CreateParticleSystem(Texture2D texture)
        {
            if (spriteBatch == null)
                throw new Exception("must initialise 'Particles' with a non-null SpriteBatch object before use");
            if (texture == null)
                throw new Exception("cannot pass null for parameter 'texture' when calling 'ParticleSystem.CreateParticleSystem'");

            ParticleSystem ps = new ParticleSystem(texture, spriteBatch, rng);
            particleSystems.Add(ps);
            return ps;
        }
 public Model3D CreateParticleSystem(int maxCount, System.Windows.Media.Color color)
 {
     ParticleSystem ps = new ParticleSystem(maxCount, color);
     this.particleSystems.Add(color, ps);
     return ps.ParticleModel;
 }