using System;
using KellysMarvelousAdventure.Utilities;
using Otter;

namespace KellysMarvelousAdventure.entities
{
    class ClickyTree : Entity
    {
        private Spritemap<string> _spriteMap;
        private Rectangle rect;

        public ClickyTree(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(100, 100, (int)Global.Type.CLICKYTREE);
            rect = new Rectangle((int)X, (int)Y, 100, 100);
            _spriteMap = new Spritemap<string>(Assets.CLICKYTREE, 100, 100);
            _spriteMap.Add("main", new int[] { 0 }, new float[] { 7, 7 });
            _spriteMap.Play("main");
            Graphic = _spriteMap;
            Layer = -2;
        }
        public override void Update()
        {
            base.Update();
            X = Scene.CameraX+570;
            Y = Scene.CameraY+70;
            rect.X = (int)X;
            rect.Y = (int)Y;

            var mouseLocation = new Vector2((int)Scene.MouseX, (int)Scene.MouseY);
            if (Util.InRect(mouseLocation, rect))
            {
                //okay, if you are hovering over the tree to click it, not sure what will happen, but that's what this is supposed to handle
                //_spriteMap.Play("hover");
                //_spriteMap.Color = Color.Gold;
                if (Global.PlayerSession.Controller.Button("LeftMouseClick").Pressed)
                {
                    SoundManager.PlayRequestedSound("_punchTree");
                    Global.Clicks++;
                    Global.once = true;
                    //if (GetEntities<ClickyBackground>().IsEmpty())
                    Scene.Add(new ClickyBackground(570, 0));
                    Scene.Add(new Leaves(570, 0));
                }
            }
            else
                ChangeAnimTo("main");
        }//end of update
        public void ChangeAnimTo(string desiredAnimation)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }
    }
}
