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; } } }
private bool InHome() { if (SupportFunc.DotInSqrt(Home.Location, Home.Width, Home.Height, ThisAnt.Location, -5)) { return(true); } return(false); }
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; }
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); }
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; } }