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

        // A particle system.
        ParticleSystem particleSystem;

        // A GraphicsDevice
        GraphicsDevice myGraphicsDevice;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new enemy shot particles object.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="graphicsDevice"></param>
        public EnemyShotParticles(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/fire";
            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 = 0;
            settings.MinColor = Color.White;
            settings.MaxColor = Color.White;
            settings.MinRotateSpeed = 1;
            settings.MaxRotateSpeed = 1;
            settings.MinStartSize = 10;
            settings.MaxStartSize = 10;
            settings.MinEndSize = 10;
            settings.MaxEndSize = 10;

            // Flame should go up in the sky
            settings.Gravity = new Vector3(0, 30, 0);

            // Use alpha blending
            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>
        /// Update the enemy shot effect.
        /// </summary>
        /// <param name="gameTime"></param>
        public void UpdateEnemyShotEffect(GameTime gameTime)
        {
            // Update
            if (gameTime != null)
            {
                this.particleSystem.Update(gameTime);
            }

        } // End of the UpdateEnemyShotEffect

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

            if (gameTime != null)
            {
                // Set camera
                this.particleSystem.SetCamera(view, projection);

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

        } // End of the DrawEnemyShotEffect method.

        #endregion
    }
}
