using LOoSE_sLOTS.objects;
using LOoSE_sLOTS.UI;
using LOoSE_sLOTS.Utilities;
using Otter;
using System;

namespace LOoSE_sLOTS.entities
{
    class RealSlotMachine : Entity
    {
        private Spritemap<string> _spriteMap;
        public int Health = 10;
        public bool IsDead;
        private int _layer;

        public RealSlotMachine(float x, float y)
        {
            X = x; Y = y;
            X = x; Y = y;
            SetHitbox(20, 40, (int)Global.Type.SLOTMACHINE);
            Collider.X = -10;
            Collider.Y = -20;
            _spriteMap = new Spritemap<string>(Assets.SLOTMACHINE, 50, 50);
            _spriteMap.Add("dead", new int[] { 5 }, new float[] { 7f, 7f });
            _spriteMap.Add("on", new int[] { 0, 1 }, new float[] { 7f, 7f });
            _spriteMap.Add("dying", new int[] { 2, 3, 4 }, new float[] { 3f, 3f });
            _spriteMap.Play("on");
            _spriteMap.Color = Color.Random;
            _spriteMap.CenterOrigin();
            Graphic = _spriteMap;
            Layer = Rand.Int(0, 2);//? will this work?
            _layer = Layer;
            //Layer = 0;//? will this work? it does because all the PUnicorns are always added AFTER my player. If they are 0 layer, they will be behind me.
            //angleInRadians = GetAngle(Rand.Float(0f, 359f));
        }

        public override void Update()
        {
            base.Update();
            if (Health <= 0 && !IsDead)
            {
                Shared.ChangeAnimTo("dying", _spriteMap);
            }
            //Console.WriteLine("_spritemap.CurrentAnim: {0}", _spriteMap.CurrentAnim);
            //Console.WriteLine("_spritemap.CurrentFrame: {0}", _spriteMap.CurrentFrame);
            //Console.WriteLine("_spritemap.CurrentFrameIndex: {0}", _spriteMap.CurrentFrameIndex);
            if (_spriteMap.CurrentAnim == "dying" && _spriteMap.CurrentFrameIndex == 2 && !IsDead)//check this TESTING
            {
                Shared.ChangeAnimTo("dead", _spriteMap);
                Collider.X = -10;
                Collider.Y = 0;
                Collider.Width = 20;
                Collider.Height = 20;
                RemoveCollider(Collider);
                IsDead = true;
                for (var i = 0; i < 10; i++)
                {
                    Global.GAME.Scene.Add(new GameCoin(X, Y, Y + 12));
                }
                SoundManager.PlayRequestedSound("_smash", .5f);
                Scene.Add(new DeadSlotMachine(X, Y, _spriteMap.Color, _layer));
                Destroy();
            }
        }//end update

        private string RandomStart()
        {
            switch (Rand.Int(1, 3))//one more than the last
            {
                case 1:
                    return "_bleep";
                case 2:
                    return "_bleepTwo";
                default:
                    return "_bleep";
            }
        }

        public bool AmICollidingWithFloor(Collider c)
        {
            var slot = c.Collide(X, Y, (int)Global.Type.SLOTMACHINE);
            var floor = c.Collide(X, Y, (int)Global.Type.SOLID);
            if (floor != null || slot != null)
                return true;
            else
                return false;
        }

        public void Destroy()
        {
            RemoveSelf();
        }

        public override void Render()
        {
            base.Render();
            //Collider.Render(Color.Blue);
            //detectionBox.Render(Color.Orange);
        }
    }
}


