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

namespace StrategicCombat.Shots
{
    /// <summary>
    /// This class represent a shot.
    /// </summary>
    public class Shot
    {

        #region Variables

        // Shot properties
        public Vector2 shotPosition;
        public Vector2 shotDirection;
        public float shotSpeed;
        public bool infiniteShotDuration;
        public int shotDuration;
        public bool isBouncing;
        public bool isExploding;

        // Collision properties
        public Point shotSize;
        public Rectangle shotCollisionRectangle;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new shot.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="direction"></param>
        /// <param name="shotSpeed"></param>
        /// <param name="shotSize"></param>
        /// <param name="shotDuration">Duration i milliseconds, 0 = infinite time</param>
        public Shot(Vector2 position, Vector2 direction, float shotSpeed, Point shotSize, bool infiniteShotDuration, int shotDuration,
            bool isBouncing, bool isExploding)
        {
            // Set values for instance variables
            this.shotPosition = position;
            this.shotDirection = direction;
            this.shotSpeed = shotSpeed;
            this.shotSize = shotSize;
            this.infiniteShotDuration = infiniteShotDuration;
            this.shotDuration = shotDuration;
            this.isBouncing = isBouncing;
            this.isExploding = isExploding;

            // Create the collision rectangle.
            this.shotCollisionRectangle = new Rectangle((int)this.shotPosition.X - (this.shotSize.X / 2), (int)this.shotPosition.Y - (this.shotSize.Y / 2),
                this.shotSize.X, this.shotSize.Y);

        }

        #endregion

        #region Methods

        /// <summary>
        /// Update the shot.
        /// </summary>
        /// <param name="gameTime"></param>
        public void UpdateShot(GameTime gameTime)
        {
            // Update shot position.
            this.shotPosition += this.shotDirection * this.shotSpeed;

            // Update the collision rectangle.
            this.shotCollisionRectangle = new Rectangle((int)this.shotPosition.X - (this.shotSize.X / 2), (int)this.shotPosition.Y - (this.shotSize.Y / 2),
                this.shotSize.X, this.shotSize.Y);

        } // End of the update shot method.

        /// <summary>
        /// Draw the shot.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="shotTexture"></param>
        public void DrawShot(SpriteBatch spriteBatch, Texture2D shotTexture)
        {
            spriteBatch.Draw(shotTexture, this.shotPosition, new Rectangle(0, 0, this.shotSize.X, this.shotSize.Y), Color.White, 0, new Vector2(this.shotSize.X / 2, this.shotSize.Y / 2), 
                1, SpriteEffects.None, 0);

        } // End of the DrawShot method.

        #endregion

    } // End of class

} // End of namespace
