using Otter;
using System;

namespace SuperRefluxPowergridDefense_.entities
{
    class BlueParticle : Entity
    {
        private bool one = true;
        private int deathTimer = 100;

        public BlueParticle(float x, float y)
        {
            X = x; Y = y;
        }

        public override void Update()
        {
            base.Update();
            var x = X; var y = Y;
            if (one)
            {
                one = false;
                var bigExplodeCount = 1;
                for (int i = 0; i < bigExplodeCount; i++)
                {
                    Scene.Add(new Particle(x, y, Assets.BLUEPARTICLE, 100, 100)
                    {
                        FrameCount = 9,
                        OffsetX = Rand.Float(-10, 10),
                        OffsetY = Rand.Float(-10, 10),
                        SpeedDir = Rand.Angle,
                        SpeedLen = Rand.Float(0, 1),
                        FinalSpeedLen = 0,
                        Layer = -10,
                        LifeSpan = Rand.Int(10, 30),
                        ScaleX = Rand.Float(0.95f, 1),
                        LockScaleRatio = true,
                        Angle = Rand.Angle,
                        FlipX = Rand.Flip,
                        FlipY = Rand.Flip,
                        Ease = Ease.ExpoOut
                    });
                }

                var smallExplodeCount = 1;
                var angleOffset = Rand.Angle;
                for (int i = 0; i < smallExplodeCount; i++)
                {
                    Scene.Add(new Particle(x, y, Assets.BLUEPARTICLE, 100, 100)
                    {
                        FrameCount = 6,
                        SpeedDir = 360f / smallExplodeCount * i + angleOffset,
                        SpeedLen = 3,
                        FinalSpeedLen = 0,
                        AdvanceSteps = 6,
                        Angle = Rand.Angle,
                        Layer = -11,
                        LifeSpan = 20,
                        LockScaleRatio = true,
                        ScaleX = 0.75f,
                        FlipX = Rand.Flip,
                        FlipY = Rand.Flip
                    });

                    var angle = Rand.Angle;
                    Scene.Add(new Particle(x, y, Assets.BLUEPARTICLE, 200, 50)
                    {
                        FrameCount = 4,
                        OriginX = 0,
                        OriginY = 25,
                        Angle = angle,
                        ScaleX = Rand.Float(0.25f, 2),
                        ScaleY = Rand.Float(0.5f, 1),
                        LifeSpan = Rand.Int(4, 30),
                        Delay = Rand.Int(3),
                        OffsetX = Util.PolarX(angle, 50),
                        OffsetY = Util.PolarY(angle, 50)
                    });
                }
            }
            if (deathTimer > 0)
                deathTimer--;
            if (deathTimer <= 0)
                Destroy();
        }

        public void Destroy()
        {
            RemoveSelf();
        }

    }
}
