Esempio n. 1
0
        /// <summary>
        /// Emits a particle.
        /// </summary>
        /// <param name="type">The particle type to emit</param>
        /// <param name="x">X point to emit from.</param>
        /// <param name="y">Y point to emit from.</param>
        public void Emit(ParticleDefinition type, float x, float y)
        {
            if (type.Owner != this)
            {
                throw new Exception("Particle type does not belong to this emitter!");
            }

            var p = CreateParticle();

            p.next = FirstActive;
            p.prev = null;
            if (p.next != null)
            {
                p.next.prev = p;
            }

            p.Definition = type;
            p.time       = 0;

            p.duration  = type.Lifetime.Duration;
            p.duration += type.Lifetime.Variance.Add * Random.Float();
            p.duration -= type.Lifetime.Variance.Subtract * Random.Float();
            if (p.duration == 0)
            {
                p.duration = DT;
            }

            float angle = type.Angle.From;

            angle += type.Angle.Variance.Add * Random.Float();
            angle -= type.Angle.Variance.Subtract * Random.Float();

            var moveAngle = type.Motion.Angle;

            moveAngle += type.Motion.AngleVariance.Add * Random.Float();
            moveAngle -= type.Motion.AngleVariance.Subtract * Random.Float();

            var distance = type.Motion.Distance;

            distance += type.Motion.DistanceVariance.Add * Random.Float();
            distance -= type.Motion.DistanceVariance.Subtract * Random.Float();

            p.initialVelocity = (distance * DT) / p.duration; // assuming XNA fixed is 60fps

            p.x = x;
            p.y = y;
            MathUtility.AngleXY(ref p.velX, ref p.velY, moveAngle, p.initialVelocity);

            p.alphaRand += type.Alpha.Variance.Add * Random.Float();
            p.alphaRand -= type.Alpha.Variance.Subtract * Random.Float();

            p.scaleRand += type.Scale.Variance.Add * Random.Float();
            p.scaleRand -= type.Scale.Variance.Subtract * Random.Float();

            p.angleRand += type.Angle.Variance.Add * Random.Float();
            p.angleRand -= type.Angle.Variance.Subtract * Random.Float();

            p.accelX = type.Motion.Acceleration.X * DT;
            p.accelY = type.Motion.Acceleration.Y * DT;

            ParticleCount++;
            FirstActive = p;
        }