using Otter;
using PpbbffttMiningHa.scenes.Levels;
using PpbbffttMiningHa.Utility;

namespace PpbbffttMiningHa.entities.MapEntities
{
    class Door : Entity
    {
        private Spritemap<string> _spriteMap;

        public Door(float x, float y)
        {
            X = x; Y = y;
            _spriteMap = new Spritemap<string>(Assets.DOOR, 300, 300);
            _spriteMap.Add("main", new int[] { 0 }, new float[] { 7f, 7f });
            _spriteMap.Play("main");
            SetHitbox(150, 150, Global.Type.DOOR);
            Collider.X = -50;//was -2
            Collider.Y = -50;//was -2
            _spriteMap.Scale = .7f;
            _spriteMap.CenterOrigin();
            Graphic = _spriteMap;
            Layer = 0;
        }

        public override void Update()
        {
            base.Update();
            var colt = Collider.Collide((int)X, (int)Y, Global.Type.PLAYER);
            if (colt != null && Global.HasKey)
            {
                Global.HasKey = false;
                Global.Score += 10;
                SoundManager.PlayRequestedSound("_unlockDoor", 2f);

                var s = Global.GAME.GetScene<LevelOne>();//if level one goto level two
                if (s != null)
                {
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new LevelTwo());
                }

                var b = Global.GAME.GetScene<LevelTwo>();//if level two go to win.
                if (b != null)
                {
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new LevelThree());
                }

                var LL = Global.GAME.GetScene<LevelThree>();//if level three go to win.
                if (LL != null)
                {
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new LevelFour());
                }
                Destroy();
            }
            else if (colt != null && !Global.HasKey)
            {
                //System.Console.WriteLine("you are colliding with the door without a key.");
                Global.WriteWord(300, 400, "You need a key!", Color.FromBytes(255, 255, 0, 255), 1, -10, Scene, 300, 12);
            }
        }

        public override void Render()
        {
            base.Render();
            //Collider.Render(Color.Gold);
        }
        public void Destroy()
        {
            RemoveSelf();
        }
    }
}

