using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AlienAttack.MonoGame.Things.Asteroids;

public class Asteroid : MoveableSprite
{
    public const int Width = 39;
    public const int Height = 37;

    protected float Rotation = 0;

    public Asteroid(int x, int y) : base(x, y)
    {
        Origin = new(Width / 2, Height / 2);
        BoundBox = new(0, 0, Width, Height);
        YVelocity = 1;
        XVelocity = 0;
    }

    public override void Draw(SpriteDrawArgs args)
    {
        Texture2D texture = args.Content.Load<Texture2D>("Sprites/Asteroid 01");
        args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);

        base.Draw(args);
    }

    public override sealed void Update(SpriteUpdateContext context)
    {
        base.Update(context);

        CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);

        if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
        {
            IsDead = true;
            return;
        }

        Rotation += 0.01f;

        if (Rotation > 360f)
        {
            Rotation = 0;
        }
    }
}