using Microsoft.Xna.Framework;
using MonoGame.FourEngine.Entities;
using System.Collections.Generic;
using System.Linq;

namespace LeMangeurDEnfants.Core.Entities
{
    public class Wall : ComponentWrapper
    {
        private Rectangle _rect;

        // Only for smaller objects! Please, don't reuse. Ok?
        public bool Collide(Point center, int radius)
        {
            if (_rect.IsEmpty)
                _rect = new Rectangle(Position, new Point(Width, Height));

            return GetCollisionPoints(center, radius)
                .Any(x => _rect.Contains(x));
        }

        public bool Collide(Point dot)
        {
            if (_rect.IsEmpty)
                _rect = new Rectangle(Position, new Point(Width, Height));
            return _rect.Contains(dot);
        }

        // Only for smaller objects! Please, don't reuse. Ok?
        protected IEnumerable<Point> GetCollisionPoints(Point center, int radius)
        {
            yield return center;
            yield return center + new Point(-radius, 0);
            yield return center + new Point(0, -radius);
            yield return center + new Point(+radius, 0);
            yield return center + new Point(0, +radius);
        }
    }
}