예제 #1
0
파일: Game.cs 프로젝트: Khaymon/SpaceWars
 public void CheckShellStrike(double deltaT, Canvas GameField)
 {
     for (int i = 0; i < Person.PlayerGun.Shells.Count; ++i)
     {
         Shell S = Person.PlayerGun.Shells[i];
         for (int j = 0; j < Asteroids.Count; ++j)
         {
             Asteroid A                = Asteroids[j];
             double   DistSquared      = Math.Pow(S.X - A.X, 2) + Math.Pow(S.Y - A.Y, 2);
             double   AsterDiamSquared = Math.Pow(A.Width / 2, 2) + Math.Pow(A.Height / 2, 2);
             if (Math.Sqrt(DistSquared) < Math.Sqrt(AsterDiamSquared))
             {
                 Strike Str = new Strike(A.X, A.Y, S.Angle);
                 Strikes.Add(Str);
                 StrikeGenerated = true;
                 A.Health       -= S.Damage;
                 GameField.Children.Remove(S.Rect);
                 Person.PlayerGun.Shells.RemoveAt(i);
                 break;
             }
             if (A.Health <= 0)
             {
                 AsteroidExplode AE = new AsteroidExplode(A.X, A.Y, A.Width + 20);
                 AsteroidExplodes.Add(AE);
                 GameField.Children.Add(AE.Rect);
                 GameField.Children.Remove(A.Rect);
                 Asteroids.RemoveAt(j);
                 Score += A.Score;
                 break;
             }
         }
     }
 }
예제 #2
0
 private void DrawAsteroidExplodes()
 {
     for (int i = 0; i < G.AsteroidExplodes.Count; ++i)
     {
         AsteroidExplode AE = G.AsteroidExplodes[i];
         Canvas.SetLeft(AE.Rect, AE.X);
         Canvas.SetTop(AE.Rect, AE.Y);
         if (!AE.IsAlive)
         {
             GameArea.Children.Remove(AE.Rect);
         }
     }
 }