Beispiel #1
0
        /// <summary>
        /// Returns the first nut in the watch area
        /// </summary>
        /// <returns>null if there is none</returns>
        public Nut GetNutInWatchArea()
        {
            foreach (var Nut in Nuts)
            {
                if (Nut.Placed && Tree.Basement.MouseHole.WatchArea.Contains(Nut.Get <Transform>().Position))
                {
                    return(Nut);
                }
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the closest nut to the given position.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="withinDistance">if != -1 only the given distance is considered</param>
        /// <returns></returns>
        public Nut GetClosestNut(Vector2 position, float withinDistance = -1)
        {
            Nut Result          = null;
            var ClosestDistance = float.MaxValue;

            foreach (var Nut in Nuts)
            {
                if (Nut.Placed)
                {
                    var Distance = (Nut.Get <Transform>().Position - position).Length();

                    if (Distance < ClosestDistance && (withinDistance == -1 || Distance <= withinDistance))
                    {
                        Result          = Nut;
                        ClosestDistance = Distance;
                    }
                }
            }

            return(Result);
        }