Esempio n. 1
0
        public static List <T> GetSpritesWithinRange <T>(Vector2 origin, float range, List <T> spriteList) where T : Sprite
        {
            List <T> sprites = new List <T>();

            foreach (T sprite in spriteList)
            {
                if (GeometricHelper.GetDistance(origin, sprite.position) <= range)
                {
                    sprites.Add(sprite);
                }
            }

            return(sprites);
        }
Esempio n. 2
0
        public static T GetClosestSpriteWithinRange <T>(Vector2 origin, float range, List <T> spriteList) where T : Sprite
        {
            T     closestSprite   = null;
            float closestDistance = float.MaxValue;
            float currentDistance = 0;

            foreach (T sprite in spriteList)
            {
                currentDistance = GeometricHelper.GetDistance(origin, sprite.position);
                if (currentDistance < closestDistance && currentDistance <= range)
                {
                    closestSprite   = sprite;
                    closestDistance = currentDistance;
                }
            }

            return(closestSprite);
        }