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

namespace Fireball
{
    class Fireball : Sprite
    {
        const int MAX_DISTANCE = 800;
        public bool Visible = false;
        public bool contact = true;

        Vector2 mStartPosition;
        Vector2 mSpeed;
        Vector2 mDirection;

        SoundEffect fireballSound;
        SoundEffectInstance fireballClip;

        public Fireball() : base("Fireball.png", new Vector2(0,0))
        {
        }

        new public void LoadContent(ContentManager theContentManager)
        {
            // fireballSound = theContentManager.Load<SoundEffect>("fireball.wav");
            base.LoadContent(theContentManager);
            Scale = 0.7f;

            fireballSound = theContentManager.Load<SoundEffect>("firee");
            fireballClip = fireballSound.CreateInstance();
            fireballClip.IsLooped = false;
        }

        public void Update(GameTime theGameTime)
        {
            if (Vector2.Distance(mStartPosition, Position) > MAX_DISTANCE)
            {
                Visible = false;
            }

            if (Visible == true)
            {
                base.Update(theGameTime, mSpeed, mDirection);
            }
        }

        public override void Draw(SpriteBatch theSpriteBatch)
        {
            if (Visible == true)
            {
                base.Draw(theSpriteBatch, SpriteEffects.None);
            }
        }

        public void Fire(Vector2 theStartPosition, Vector2 theSpeed, Vector2 theDirection)
        {
            fireballClip.Play();
            Position = theStartPosition;
            mStartPosition = theStartPosition;
            mSpeed = theSpeed;
            mDirection = theDirection;
            Visible = true;
        }
    }
}
