using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace FredriksdalAssault2
{
    public class BloodParticles
    {
        #region Variables

        // A particle system.
        ParticleSystem particleSystem;

        // A GraphicsDevice
        GraphicsDevice myGraphicsDevice;

        #endregion

        #region Constructors

        // Create a new blood particles object.
        public BloodParticles(ContentManager content, GraphicsDevice graphicsDevice)
        {
            // Set the graphicsDevice
            this.myGraphicsDevice = graphicsDevice;

            // Create a new particle settings object.
            ParticleSettings settings = new ParticleSettings();

            // Change the settings for the particle settings object.
            settings.TextureName = "Textures/blood";
            settings.MaxParticles = 100;
            settings.Duration = TimeSpan.FromSeconds(4);
            settings.DurationRandomness = 1;
            settings.MinHorizontalVelocity = 0;
            settings.MaxHorizontalVelocity = 20;
            settings.MinVerticalVelocity = -20;
            settings.MaxVerticalVelocity = -5;
            settings.EndVelocity = 0;
            settings.MinColor = Color.White;
            settings.MaxColor = Color.White;
            settings.MinRotateSpeed = -1;
            settings.MaxRotateSpeed = 1;
            settings.MinStartSize = 10;
            settings.MaxStartSize = 20;
            settings.MinEndSize = 1;
            settings.MaxEndSize = 10;

            // Make the blood fall to the ground.
            settings.Gravity = new Vector3(0, -10, 0);

            // Use additive blending.
            //settings.BlendState = BlendState.Additive;

            // Create a new particle system.
            this.particleSystem = new ParticleSystem(content, graphicsDevice, settings);

        }

        #endregion

        #region Methods

        /// <summary>
        /// Add blood particles
        /// </summary>
        /// <param name="numberOfParticles"></param>
        /// <param name="position"></param>
        public void AddParticles(int numberOfParticles, Vector3 position)
        {
            // Add a number of particles
            for (int i = 0; i < numberOfParticles; i++)
            {
                // Add particle, speed of five
                this.particleSystem.AddParticle(position, new Vector3(3, -30, 3));
            }
        }

        /// <summary>
        /// Draw the blood effect.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        /// <param name="position"></param>
        public void DrawBloodEffect(GameTime gameTime, Matrix view, Matrix projection)
        {

            // Update
            this.particleSystem.Update(gameTime);

            // Set camera
            this.particleSystem.SetCamera(view, projection);

            // Draw
            this.particleSystem.Draw(gameTime, this.myGraphicsDevice);
        }

        #endregion
    }
}
