Exemplo n.º 1
0
            /// <summary>
            /// Creates a new particle with a random start location, and verticle velocity
            /// </summary>1
            /// <param name="newParticle"></param>
            protected override void NewParticle(XNACS1Particle newParticle)
            {
                newParticle.CenterX += XNACS1Base.RandomFloat(-(m_FireWidth / 2), (m_FireWidth / 2));
                newParticle.CenterY += XNACS1Base.RandomFloat(-1, 1);
                Vector2 velocity = m_FireDirection * XNACS1Base.RandomFloat(0, 1);


                velocity                *= m_Speed;
                newParticle.Velocity     = velocity;
                newParticle.ShouldTravel = true;
            }
Exemplo n.º 2
0
            /// <summary>
            /// Overloaded NewParticle Method, gives explosion particles initial velocity and sets
            /// ShouldTravel = true.
            /// </summary>
            /// <param name="newParticle"></param>
            protected override void NewParticle(XNACS1Particle newParticle)
            {
                newParticle.CenterX += XNACS1Base.RandomFloat(-m_Radius / 10, m_Radius / 10);
                newParticle.CenterY += XNACS1Base.RandomFloat(-m_Radius / 10, m_Radius / 10);
                Vector2 randomVelocity = new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1));

                randomVelocity.Normalize();
                randomVelocity          *= m_ExplodeSpeed * XNACS1Base.RandomFloat(.5f, 1);
                newParticle.Velocity     = randomVelocity;
                newParticle.ShouldTravel = true;
            }
Exemplo n.º 3
0
        /// <summary>
        /// Overloaded TravelPrimitive for Particles.
        /// Moves the particle during each update cycle. This function is automacially called for all visible
        /// particle. Default behavior is to move the particle if:
        ///     . Primitive is visible (invivislble primitive is not updated)
        ///     . ShouldTravel is true
        ///     . HasNonZeroVelocity() is true
        /// This method moves the particle in the direction of its velocity and also displaces it according to the ParticleTravelMode chosen.
        /// </summary>
        public override void TravelPrimitive()
        {
            if (m_ParticleLife > 0)
            {
                m_ParticleLife--;
            }
            if (Visible && ShouldTravel)
            {
                m_TravelTime++;
                if (HasNonZeroVelocity())
                {
                    m_Center += Velocity;
                }

                if (m_TravelMode != ParticleTravelMode.Linear)
                {
                    Vector2 velocityNormal = Vector2.Zero;
                    Vector2 velocityFront;
                    if (m_LastCenter == m_Center)
                    {
                        velocityFront = VelocityDirection;
                    }
                    else
                    {
                        velocityFront = (m_Center - m_LastCenter);
                    }
                    velocityNormal.X = -(velocityFront).Y;
                    velocityNormal.Y = (velocityFront).X;
                    velocityNormal.Normalize();

                    //not dependent on velocity;
                    switch (m_TravelMode)
                    {
                    case ParticleTravelMode.RandomDisplace:
                        m_Displacement += new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1)) * m_DisplacementFrequency;
                        if (m_Displacement.Length() > m_DisplacementAmplitude)
                        {
                            m_Displacement.Normalize();
                        }
                        break;

                    case ParticleTravelMode.TransverseSine:
                        m_Displacement = velocityNormal * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.CompressionSine:
                        m_Displacement = Vector2.Normalize(m_Center - m_LastCenter) * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.VerticalSine:
                        m_Displacement = Vector2.UnitY * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.HorizontalSine:
                        m_Displacement = Vector2.UnitX * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;
                    }
                }
                m_LastCenter = m_Center;
            }
        }