Exemplo n.º 1
0
        public void LookForTarget(Player player)
        {
            if (target == null)
            {
                List <Unit> enemiesInSight = new List <Unit>();

                foreach (Unit enemy in player.units)
                {
                    if (Sight.Contains(enemy.pos))
                    {
                        enemiesInSight.Add(enemy);
                    }
                }

                if (enemiesInSight.Count == 0)
                {
                    return;
                }

                float shortest_distance = Sight.Radius;
                foreach (Unit enemy in enemiesInSight)
                {
                    float distance = (enemy.pos - pos).Length();
                    if (distance < shortest_distance)
                    {
                        shortest_distance = distance;
                        target            = enemy;
                    }
                }
            }
        }
Exemplo n.º 2
0
 protected bool EnemyInSight(Computer p2)
 {
     foreach (Unit unit in p2.units)
     {
         if (Sight.Contains(unit.pos))
         {
             return(true);
         }
     }
     return(false);
 }