Exemple #1
0
        public void QueryLine(float x1, float y1, float x2, float y2, QuerySelector selector, float width, Func <Entity, bool> callback)
        {
            var start     = new Vector2(x1, y1);
            var line      = new Vector2(x2 - x1, y2 - y1);
            var length    = line.Length();
            var increment = 1.0f / (length / (width * 2));
            var pct       = 0.0f;

            while (pct <= 1.0f)
            {
                var pos  = start + line * pct;
                var stop = false;
                QueryRect(pos.X - width / 2, pos.Y - width / 2, Mathf.Ceiling(width), Mathf.Ceiling(width), selector, (entity) =>
                {
                    if (callback(entity))
                    {
                        stop = true;
                        return(true);
                    }
                    return(false);
                });
                if (stop)
                {
                    return;
                }
                pct += increment;
            }
        }
Exemple #2
0
        public QueryResult QueryLine(float x1, float y1, float x2, float y2, QuerySelector selector, float width = 1.0f)
        {
            var result = QueryResult.None;

            QueryLine(x1, y1, x2, y2, selector, width, (entity) =>
            {
                result = new QueryResult(entity);
                return(true);
            });
            return(result);
        }
Exemple #3
0
        public QueryResult QueryCircle(Vector2 position, float radius, QuerySelector selector)
        {
            var result = QueryResult.None;

            QueryCircle(position, radius, selector, (entity) =>
            {
                result = new QueryResult(entity);
                return(true);
            });
            return(result);
        }
Exemple #4
0
 public void QueryRect(float x, float y, int width, int height, QuerySelector selector, Func <Entity, bool> callback)
 {
     selector.Select(this, (entity) =>
     {
         if (entity.CollideRect(x, y, width, height) != HitInfo.None)
         {
             return(callback(entity));
         }
         return(false);
     });
 }
Exemple #5
0
        public QueryResult QueryRect(float x, float y, int width, int height, QuerySelector selector)
        {
            var result = QueryResult.None;

            QueryRect(x, y, width, height, selector, (entity) =>
            {
                result = new QueryResult(entity);
                return(true);
            });
            return(result);
        }
Exemple #6
0
        public void QueryCircle(Vector2 position, float radius, QuerySelector selector, Func <Entity, bool> callback)
        {
            var radiusSquared = radius * radius;

            selector.Select(this, (entity) =>
            {
                if (position.DistanceSquared(entity.Position) < radiusSquared)
                {
                    return(callback(entity));
                }
                return(false);
            });
        }
Exemple #7
0
 public void QueryRect(Rectangle rect, QuerySelector selector, Func <Entity, bool> callback)
 {
     QueryRect(rect.X, rect.Y, rect.Width, rect.Height, selector, callback);
 }
Exemple #8
0
 public QueryResult QueryRect(Rectangle rect, QuerySelector selector)
 {
     return(QueryRect(rect.X, rect.Y, rect.Width, rect.Height, selector));
 }