using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace TribbleExtinction
{
    public class EffectLibrary
    {
        Game1 game;
        Texture2D RedBlob;
        Texture2D Dust;
        Texture2D Blood;
        Texture2D Poison;

        public EffectLibrary()
        {
            RedBlob = Program.masterGame.Content.Load<Texture2D>("Explosion");
            Dust = Program.masterGame.Content.Load<Texture2D>("Dust");
            Blood = Program.masterGame.Content.Load<Texture2D>("Blood");
            Poison = Program.masterGame.Content.Load<Texture2D>("Poison");
            
        }

        public Effect CreateRedBlob(Vector2 Positon)
        {
            Effect ef = new Effect();
            ef.duration = 1.0f;
            ef.progress = 1.5f;
            ef.scale = 2.5f;
            ef.position = Positon;
            ef.spin = 1.0f;
            ef.texture = RedBlob;

            return ef;
        }

        public void CreateRedBlobExplosion(Vector2 Positon)
        {
            for (int i = 0; i < 10; i++)
            {
                float x = (float)Program.game.rand.Next(-10, 10);
                float y = (float)Program.game.rand.Next(-10, 10);
                x = x * x / 3 * Math.Sign(x);
                y = y * y / 3 * Math.Sign(y);
                Vector2 Offset = new Vector2(x, y);
                Effect ef = CreateRedBlob(Positon + Offset);
                ef.progress -= i / 20f;
                ef.scale = 2.5f - (i / 10f);
                if ((i & 1) == 1)
                    ef.spin = -1.0f;
                Program.game.EffectList.Add(ef);
            }
        }

        public void CreateHugeRedBlob(Vector2 Positon)
        {
            float x = (float)Program.game.rand.Next(-15, 15);
            float y = (float)Program.game.rand.Next(-15, 15);
            x = x * x / 3 * Math.Sign(x);
            y = y * y / 3 * Math.Sign(y);
            Vector2 Offset = new Vector2(x, y);
            Effect ef = CreateRedBlob(Positon + Offset);
            ef.progress = 1.5f;
            ef.scale = 10.0f;
            Program.game.EffectList.Add(ef);
        }

        public Effect CreateDust(Vector2 Positon)
        {
            Effect ef = new Effect();
            ef.duration = 3.0f;
            ef.progress = 2.5f;
            ef.scale = 2.5f;
            ef.position = Positon;
            ef.spin = 0f;
            ef.texture = Dust;

            return ef;
        }

        public void CreateDustPuffs(Vector2 Positon)
        {
            for (int i = 0; i < 40; i++)
            {
                float x = (float)Program.game.rand.Next(-10, 10);
                float y = (float)Program.game.rand.Next(-10, 10);
                x = x * x / 4 * Math.Sign(x);
                y = y * y / 4 * Math.Sign(y);

                Vector2 Offset = new Vector2(x, y);
                Effect ef = CreateDust(Positon + Offset);
                ef.progress -= i / 70f;
                ef.scale = 2.5f - (Math.Abs(x) + Math.Abs(y)) / 38;

                Program.game.EffectList.Add(ef);
            }
        }
        
        public void CreateBloodSplat(Vector2 Positon)
        {
            Effect ef = new Effect();
            ef.duration = 0.3f;
            ef.progress = 1.0f;
            ef.scale = (float)(Program.game.rand.NextDouble() + 1.0f) / 4;
            ef.position = Positon;
            ef.angle = (float)Program.game.rand.NextDouble() * 6.28f;
            ef.texture = Blood;

            Program.game.EffectList.Add(ef);
        }
        public void CreatePoisonSplat(Vector2 Positon)
        {
            Effect ef = new Effect();
            ef.duration = 0.3f;
            ef.progress = 1.0f;
            ef.scale = (float)Program.game.rand.NextDouble() + 1.0f;
            ef.position = Positon;
            ef.angle = (float)Program.game.rand.NextDouble() * 6.28f;
            ef.spin = 0.5f;
            ef.texture = Poison;

            Program.game.EffectList.Add(ef);
        }
    }
}
