Exemplo n.º 1
0
        private static IEnumerator<bool> LazyHomingToEnemy(PlayerUser par, PlayerBullet b, double startAngle, double startSpeed, int delay, double homingSpeed)
        {
            for (int i = 0; i < delay; i++)
            {
                b.X += Math.Cos(startAngle) * startSpeed;
                b.Y += Math.Sin(startAngle) * startSpeed;
                yield return true;
            }

            var t = par.ParentManager
                .Where(p => p.MyKind != b.MyKind && ((p.DamageKind & b.MyKind) != 0))
                .OrderBy(p => (p.X - b.X) * (p.X - b.X) + (p.Y - b.Y) * (p.Y - b.Y))
                .FirstOrDefault();
            var ang = 0.0;
            if (t == null)
            {
                ang = rnd.NextDouble() * Math.PI * 2;
            }
            else
            {
                ang = Math.Atan2(t.Y - b.Y, t.X - b.X);
            }

            while (true)
            {
                b.X += Math.Cos(ang) * homingSpeed;
                b.Y += Math.Sin(ang) * homingSpeed;
                yield return true;
            }
        }
Exemplo n.º 2
0
 private static IEnumerator<bool> Linear(UserSprite par, PlayerBullet b, double angle, double speed, int time)
 {
     for (int i = 0; i < time; i++)
     {
         b.X += Math.Cos(angle) * speed;
         b.Y += Math.Sin(angle) * speed;
         yield return true;
     }
     b.IsDead = true;
     yield break;
 }
Exemplo n.º 3
0
 private static IEnumerator<bool> HomingFunction(UserSprite us, PlayerBullet b)
 {
     var speed = 12.0;
     var curve = 0.03;
     var tl = us.ParentManager.OfType<EnemyUser>()
         .OrderBy(p =>
         {
             var x = p.X - b.X;
             var y = p.Y - b.Y;
             return Math.Sqrt(x * x + y * y);
         }).FirstOrDefault();
     var hm = tl != null;
     while (true)
     {
         if (hm && !tl.IsDead)
         {
             var ta = Math.Atan2(tl.Y - b.Y, tl.X - b.X) - b.Angle;
             if (ta <= 0)
             {
                 b.Angle -= curve;
             }
             else
             {
                 b.Angle += curve;
             }
         }
         b.X += Math.Cos(b.Angle) * speed;
         b.Y += Math.Sin(b.Angle) * speed;
         yield return true;
     }
 }