Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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;
            }
        }