예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="particleTexture"></param>
        /// <param name="position"></param>
        public FireworkParticleSystem(SpriteBatch spriteBatch, Texture2D particleTexture, Vector2 position)
        {
            m_spriteBatch = spriteBatch;
            m_particleTexture = particleTexture;

            // Generate a color value
            double randomValue = m_random.NextDouble();
            if (randomValue <= 0.33) // Yellow to red
            {
                m_startColor = new Color(1.0f, 0.0f, 0.0f);
                m_targetColor = new Color(1.0f, 1.0f, 0.0f);
            }
            else if (randomValue <= 0.66) // Green to yellow
            {
                m_startColor = new Color(0.0f, 1.0f, 0.0f);
                m_targetColor = new Color(1.0f, 1.0f, 0.0f);
            }
            else // Black to Blue
            {
                m_startColor = new Color(1.0f, 1.0f, 0.0f);
                m_targetColor = new Color(0.0f, 0.0f, 1.0f);
            }

            // Generate random direction & speed for new particle
            float rndX = 1 * ((float)m_random.NextDouble() - 0.5f);
            float rndY = -2f + 1 * ((float)-m_random.NextDouble());

            // Create new particle at system's starting position
            FireworkParticle part = new FireworkParticle(position, // With generated direction and speed
                    new Vector2(rndX * 45.0f, rndY * 90.0f), m_startColor, m_targetColor,
                // And a random starting life
                (float)(m_random.NextDouble() * 1.6)+0.9f);//m_random.Next(50));

            // Create particle, and add it to the list of particles
            m_particles.Add(part);
        }
예제 #2
0
        /// <summary>
        /// Create Rain Explosion particle system particles based on source position
        /// </summary>
        /// <param name="position">Source position for first spawn point</param>
        private void CreateExplosionRain(Vector2 position)
        {
            // Create all particles
            for (int i = 0; i < MAX_NUMBER_OF_PARTICLES_RAIN; i++)
            {
                // Generate random direction & speed for new particle
                float rndX = 2 * ((float)m_random.NextDouble() - 0.5f);
                float rndY = 2 * ((float)m_random.NextDouble() - 0.5f);

                // Create new particle at system's starting position
                FireworkParticle part = new FireworkParticle(position,
                    // With generated direction and speed
                    new Vector2(rndX * 180.0f, rndY * 180.0f), m_startColor, m_targetColor,
                    // And a random starting life
                    (float)(m_random.NextDouble() * 1.5));
                m_particles.Add(part);
            }
        }
예제 #3
0
 /// <summary>
 /// Create Circle Explosion particle system particles based on source position
 /// </summary>
 /// <param name="position">Source position for first spawn point</param>
 private void CreateExplosionCircle(Vector2 position)
 {
     // Create all particles
     for (int i = 0; i < MAX_NUMBER_OF_PARTICLES_CIRCLE; i++)
     {
         FireworkParticle newPart = new FireworkParticle(position,
             // With generated direction and speed
             new Vector2((float)Math.Cos(Math.PI * 2 * i / MAX_NUMBER_OF_PARTICLES_CIRCLE) * 175.0f,
                        (((float)Math.Sin(Math.PI * 2 * i / MAX_NUMBER_OF_PARTICLES_CIRCLE) / 2) - 0.75f) * 175.0f),
                        m_startColor, m_targetColor,
                        (float)(m_random.NextDouble() * 1.0));
         m_particles.Add(newPart);
     }
 }