Example #1
0
        public void fillSensorsFront(List <Prey> agents)
        {
            float testangle;
            float distance;

            for (int prey = 0; prey < agents.Count; prey++)
            {
                Prey a = agents[prey];


                distance = Utilities.Distance(this, a);

                //while going through prey, they save the closest predator to save time later
                if (distance < a.closestPredDist)
                {
                    a.closestPredDist = distance;
                    a.closestPred     = this;
                }

                if (distance > radius)
                {
                    continue;
                }

                testangle = heading - Utilities.piOverTwo;
                float angle = (float)Math.Atan2(a.y - y, a.x - x);
                if (angle < 0)
                {
                    angle += Utilities.twoPi;
                }
                for (int j = 0; j < sensors.Length; j++, testangle += angledelta)
                {
                    if (isInSensor(testangle, angle))
                    {
                        //if the agent is in the middle sensor save for later
                        if (j == 2)
                        {
                            sensedAgents.Add(a);
                        }
                        float dist = 1 - (distance / (float)radius);
                        sensors[j] += dist * dist;
                        break;
                    }
                }
            }
        }
Example #2
0
 public void addEnemy(Prey enemy)
 {
     Enemy.Add(enemy);
 }
Example #3
0
 public void addEnemy(Prey enemy)
 {
     Enemy.Add(enemy);
 }