public bool HasClearShot(TankUnit enemyUnit)
 {
     if (Match.map.GetObstacleDistance(Tank.GetPosition(), enemyUnit.Tank.GetPosition()) == null)
     {
         return(true);
     }
     return(false);
 }
            public void MoveTowards(Vector2 point)
            {
                // detect and avoid obstacles
                Vector2 detectionOffset = Vector2.Normalize(point - Tank.GetPosition()) * obstacleDetectionDistance;

                var obstacleDistance = Match.map.GetObstacleDistance(Tank.GetPosition(), Tank.GetPosition() + detectionOffset);

                // obstacle detected
                if (obstacleDistance != null)
                {
                    // try change direction
                    float rotationDegrees     = 1;
                    var   newDetectionOffset  = Tools.RotateVector2(detectionOffset, rotationDegrees);
                    var   newObstacleDistance = Match.map.GetObstacleDistance(Tank.GetPosition(), Tank.GetPosition() + newDetectionOffset);

                    // obstacle no longer detected
                    if (newObstacleDistance == null)
                    {
                        Tank.SetPosition(Tank.GetPosition() + Vector2.Normalize(newDetectionOffset) * Speed);
                        return;
                    }
                    // obstacle even closer, reverse direction
                    else if (newObstacleDistance < obstacleDistance)
                    {
                        rotationDegrees = -rotationDegrees;
                    }

                    newDetectionOffset = detectionOffset;
                    float totalRotation = 0;

                    // change direction until no obstacle is detected
                    while (totalRotation < 360)
                    {
                        newDetectionOffset  = Tools.RotateVector2(newDetectionOffset, rotationDegrees);
                        newObstacleDistance = Match.map.GetObstacleDistance(Tank.GetPosition(), Tank.GetPosition() + newDetectionOffset);

                        if (newObstacleDistance == null)
                        {
                            Tank.SetPosition(Tank.GetPosition() + Vector2.Normalize(newDetectionOffset) * Speed);
                            return;
                        }

                        totalRotation += rotationDegrees;
                    }
                }
                // obstacle not detected
                else
                {
                    Tank.SetPosition(Tank.GetPosition() + Vector2.Normalize(detectionOffset) * Speed);
                }
            }
 public bool IsInEnemyRange(TankUnit enemyUnit)
 {
     return(enemyUnit.Range > Vector2.Distance(Tank.GetPosition(), enemyUnit.Tank.GetPosition()));
 }