} // end method CheckForInvadersShot /// <summary> /// This method checks to see if an invader was hit by bomb, /// which expands outward and is different from a shot. /// </summary> private void CheckForInvadersBombed() { for (int i = playerBombs.Count - 1; i >= 0; i--) { if (!playerBombs[i].Exploded) { List<Point> bombLocations = playerBombs[i].AllCollisionPoints; AreaUser expandingBomb = playerBombs[i]; var invaderCollisions = from hitInvader in invaders where WasHit(hitInvader, expandingBomb) select hitInvader; if (invaderCollisions.Count() > 0) { gotPointsFromShots = false; if (!playerBombs[i].Expanding) playerBombs[i].Expanding = true; List<Invader> deadInvaders = new List<Invader>(); foreach (var deadInvader in invaderCollisions) deadInvaders.Add(deadInvader); foreach (Invader deadInvader in deadInvaders) { KillInvader(deadInvader); } // end foreach } // end if } // If the bomb HAS exploded, remove it. else playerBombs.Remove(playerBombs[i]); }// end for } // end method CheckForInvadersBombed
/// <summary> /// This method checks to see if an invader was hit by an attack. /// </summary> /// <param name="hitInvader">The invader to check for hits.</param> /// <param name="attackArea">The AreaUser reference to use to get /// a list of points representing all points along the outer edge of the attack.</param> /// <returns>A boolean indicating whether or not the invader was hit.</returns> private bool WasHit(Invader hitInvader, AreaUser attackArea) { List<Point> hitPointList = attackArea.AllCollisionPoints; List<Point> invaderCollisionList = hitInvader.AllCollisionPoints; foreach (Point point in hitPointList) if (hitInvader.Area.Contains(point)) return true; foreach (Point point in invaderCollisionList) if (attackArea.Area.Contains(point)) return true; return false; }