示例#1
0
 private Enemy FindTarget()
 {
     if (enemies.Count > 0)
     {
         Enemy  nearestEnemy         = enemies[0];
         double nearestEnemyDistance = GameHelper.GetDistance(Position, nearestEnemy.Position);
         foreach (var enemy in enemies)
         {
             double distance = GameHelper.GetDistance(Position, enemy.Position);
             if (distance < nearestEnemyDistance)
             {
                 nearestEnemy         = enemy;
                 nearestEnemyDistance = distance;
             }
         }
         if (nearestEnemyDistance < range)
         {
             return(nearestEnemy);
         }
     }
     return(null);
 }
示例#2
0
        private Tuple <Point, SnapAlignment> GetMoveAlongBorderResult(Wall wall)
        {
            double actualWidth    = (wall.Center.X - wall.Position.X) * 2;
            double actualHeight   = (wall.Center.Y - wall.Position.Y) * 2;
            double maxDistance    = 22;
            Point  leftBorderPos  = new Point(GameHelper.LeftOfGame, cursorPosition.Y - actualHeight / 2);
            Point  topBorderPos   = new Point(cursorPosition.X - actualWidth / 2, GameHelper.TopOfGame);
            Point  rightBorderPos = new Point(GameHelper.RightOfGame - actualWidth, cursorPosition.Y - actualHeight / 2);

            if (GameHelper.GetDistance(leftBorderPos, new Point(cursorPosition.X - (actualWidth / 2), cursorPosition.Y - (actualHeight / 2))) < maxDistance)
            {
                return(new Tuple <Point, SnapAlignment>(leftBorderPos, SnapAlignment.RightBottom));
            }
            if (GameHelper.GetDistance(topBorderPos, new Point(cursorPosition.X - (actualWidth / 2), cursorPosition.Y - (actualHeight / 2))) < maxDistance)
            {
                return(new Tuple <Point, SnapAlignment>(topBorderPos, SnapAlignment.RightBottom));
            }
            if (GameHelper.GetDistance(rightBorderPos, new Point(cursorPosition.X - (actualWidth / 2), cursorPosition.Y - (actualHeight / 2))) < maxDistance)
            {
                return(new Tuple <Point, SnapAlignment>(rightBorderPos, SnapAlignment.TopLeft));
            }
            return(null);
        }
示例#3
0
 public override void Update()
 {
     base.Update();
     if (currentEnemyTarget == null || currentEnemyTarget != null && currentEnemyTarget.Destroyed || GameHelper.GetDistance(Position, currentEnemyTarget.Position) > range)
     {
         projectileLauncher.Fire = false;
         currentEnemyTarget      = FindTarget();
     }
     else
     {
         projectileLauncher.Target = currentEnemyTarget.Collider.Center;
         projectileLauncher.Fire   = true;
     }
     projectileLauncher.Update();
 }