using Microsoft.Xna.Framework;
using MonoGame.FourEngine;

namespace Raycast.Win32.Entities
{
    partial class Enemy
    {
        protected class DeathState : EnemyStateBase
        {
            private double _msPassed;

            private bool _disabled;

            public DeathState(Enemy enemy) : base(enemy)
            {
            }

            public override void OnEnter()
            {
                Enemy.Frame = new Point(0, Enemy.AnimationMap[EnemyState.Death].Start);

                MessageCenter.TriggerEnemyDead(this);
            }

            public override void OnUpdate(UpdateEventArgs args)
            {
                if (Enemy.Scene == null) return;

                if (_disabled) return;

                Enemy.VerticalPosition = Enemy.MinVerticalPosition;

                _msPassed += args.DeltaTime.TotalMilliseconds;

                var frameX = (int)(_msPassed / 128);
                if (frameX < Enemy.Sprite.FrameCount.X)
                {
                    Enemy.Frame = new Point(frameX, Enemy.Frame.Y);
                }
                else
                {
                    _disabled = true;
                }
            }
        }
    }
}