using MonoGame.FourEngine.Entities;
using MonoGame.FourEngine.Resources;
using Microsoft.Xna.Framework;
using MonoGame.FourEngine.Components;
using static MonoGame.FourEngine.Components.AnimationComponent;

namespace MonoGame.FourEngine.Sample.Win32.Entities
{
    public class AlienEntity : BasicEntity
    {
        private bool _isAlive = true;

        protected override SpriteDefinition SpriteDefinition
            => new SpriteDefinition
            {
                FileName = Resources.Sprites.AlienSprite,
                Size = new Point(40),
                Margin = new Point(1)
            };

        public AlienEntity()
        {    
            AnimationComponent.StartAnimation(
                FramedAnimation.GenerateRange(new Range(0, 4), 0, 100, true));
        }

        public override void OnPrimaryClick(ClickedEventArgs args)
        {
            base.OnPrimaryClick(args);
            if (!_isAlive) return;
            _isAlive = false;
            AnimationComponent.StartAnimation(
                FramedAnimation.GenerateRange(new Range(0, 4), 2, 100, false));
            args.Pointer.PrimaryClickCancellable.Cancel();
        }
    }
}