Пример #1
0
        public bool EatableObjectIsIn(EatableObject eatableObject)
        {
            double eatableObjectLeftX   = eatableObject.Position.X - eatableObject.Radius;
            double eatableObjectRightX  = eatableObject.Position.X + eatableObject.Radius;
            double eatableObjectBottomY = eatableObject.Position.Y - eatableObject.Radius;
            double eatableObjectTopY    = eatableObject.Position.Y + eatableObject.Radius;

            bool horizontallyInside = (leftX <= eatableObjectLeftX) && (eatableObjectRightX <= rightX);
            bool verticallyInside   = (bottomY <= eatableObjectBottomY) && (eatableObjectTopY <= topY);

            return(horizontallyInside && verticallyInside);
        }
Пример #2
0
        public void EatObject(EatableObject other)
        {
            if (other == null)
            {
                return;
            }

            OnCircleAte?.Invoke(this, new CircleAteEventArgs(this));

            this.Radius = Math.Sqrt(Math.Pow(this.Radius, 2) + Math.Pow(other.Radius, 2));

            other.Remove();
        }
Пример #3
0
        public bool CanEatOtherObject(EatableObject other)
        {
            if (this.Radius <= other.Radius)
            {
                return(false);
            }

            double otherLeftX   = other.Position.X - other.Radius;
            double otherRightX  = other.Position.X + other.Radius;
            double otherBottomY = other.Position.Y - other.Radius;
            double otherTopY    = other.Position.Y + other.Radius;

            bool horizontallyInside = (this.Position.X - Radius < otherLeftX) && (otherRightX < this.Position.X + Radius);
            bool verticallyInside   = (this.Position.Y - Radius < otherBottomY) && (otherTopY < this.Position.Y + Radius);

            return(horizontallyInside && verticallyInside);
        }
Пример #4
0
 public void SwallowEatableObject(EatableObject swallowed)
 {
     this.Radius = Math.Sqrt(Math.Pow(this.Radius, 2) + Math.Pow(swallowed.Radius, 2));
     swallowed.Remove();
 }