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 ShotParticles
    {
        #region Variables

        // A particle system.
        ParticleSystem particleSystem;

        // A GraphicsDevice
        GraphicsDevice myGraphicsDevice;

        #endregion

        #region Constructors

        // Create a new blood particles object.
        public ShotParticles(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/shootEffect"; //shootEffect
            settings.MaxParticles = 100;
            settings.Duration = TimeSpan.FromSeconds(0.4f);
            settings.DurationRandomness = 0;
            settings.MinHorizontalVelocity = 0;
            settings.MaxHorizontalVelocity = 0;
            settings.MinVerticalVelocity = 0;
            settings.MaxVerticalVelocity = 0;
            settings.EndVelocity = 1000;
            settings.MinColor = Color.White;
            settings.MaxColor = Color.White;
            settings.MinRotateSpeed = 0;
            settings.MaxRotateSpeed = 0;
            settings.MinStartSize = 5f;
            settings.MaxStartSize = 5f;
            settings.MinEndSize = 5f;
            settings.MaxEndSize = 5f;

            // Shots shall not fall to the ground
            settings.Gravity = new Vector3(0, 0, 0);

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

            // 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, Vector3 direction)
        {
            // Add a number of particles
            for (int i = 0; i < numberOfParticles; i++)
            {
                // Add particle, speed of five
                this.particleSystem.AddParticle(position, direction);
            }
        }

        /// <summary>
        /// Draw the shot effect.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        /// <param name="position"></param>
        public void DrawShotEffect(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
    }
}
