예제 #1
0
        public void SerchLeaf()
        {
            if (IsFear)
            {
                Brain.PushState(() => { RunAway(); });
            }
            if (TargetLeaf != null)
            {
                Brain.PushState(() => { GoHomeWithLeaf(); });
            }

            ChFear();
            Control foundLeaf = FoundLeaf();

            if (foundLeaf == null)
            {
                Serch();
            }
            else
            {
                GoOneStepToTarget(Speed);
                Point foundLeafCentre = SupportFunc.getCentre(foundLeaf.Location, foundLeaf.Width, foundLeaf.Height);
                if (!InTarget())
                {
                    Target = foundLeafCentre;
                }

                if (SupportFunc.DotInSqrt(ThisAnt.Location, ThisAnt.Width, ThisAnt.Height, foundLeafCentre, 5))
                {
                    TargetLeaf = foundLeaf;
                }
            }
        }
예제 #2
0
 private bool InHome()
 {
     if (SupportFunc.DotInSqrt(Home.Location, Home.Width, Home.Height, ThisAnt.Location, -5))
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
        private void ChFear()
        {
            Point antCentre = SupportFunc.getCentre(ThisAnt.Location, ThisAnt.Width, ThisAnt.Height);

            if (SupportFunc.InRadius(antCentre, Enemy, Visibility))
            {
                IsFear     = true;
                Target     = Enemy;
                TargetLeaf = null;
                return;
            }
            IsFear = false;
        }
예제 #4
0
 private Control FoundLeaf()
 {
     foreach (Control leaf in Leafs)
     {
         if (!leaf.Enabled)
         {
             continue;
         }
         Point antCentre  = SupportFunc.getCentre(ThisAnt.Location, ThisAnt.Width, ThisAnt.Height);
         Point leafCentre = SupportFunc.getCentre(leaf.Location, leaf.Width, leaf.Height);
         if (SupportFunc.InRadius(antCentre, leafCentre, Visibility))
         {
             return(leaf);
         }
     }
     return(null);
 }
예제 #5
0
        public void GoHomeWithLeaf()
        {
            if (TargetLeaf == null)
            {
                Brain.PushState(() => { SerchLeaf(); });
            }
            Point homeCentre = SupportFunc.getCentre(Home.Location, Home.Width, Home.Height);

            Target = homeCentre;
            GoOneStepToTarget(Speed);
            if (InHome())
            {
                SetRandomTarget();
                TargetLeaf.Enabled = false;
                TargetLeaf         = null;
                Brain.popState();
            }
            else
            {
                TargetLeaf.Location = ThisAnt.Location;
            }
        }