/// <summary> /// Determines all the projectiles targeting the given nightmare /// </summary> /// <param name="nmIndex">Index of the nightmare</param> /// <returns>A list containing all projectiles</returns> private List<Projectile> GetProjectiles(Nightmare nm) { List<Projectile> pList = new List<Projectile>(); foreach (Projectile p in projectiles) { if (p.Target == nm) { pList.Add(p); } } return pList; }
public Projectile(Texture2D texture, Vector2 position, Nightmare target, Ability projectileAbility) : base(texture, position) { this.target = target; ProjectileAbility = projectileAbility; }
/// <summary> /// Performs the following: /// 1)Removes all projectiles targeting the given nightmare. /// 2)All towers targeting this nightmare are set to NoTarget /// 3)Adds currency value of the nightmare to the player's wallet /// 4)Removes the nightmare from the level /// </summary> /// <param name="nightmareIndex"></param> private void DestroyNightmare(Nightmare nightmare) { Projectile p; foreach (Tower t in towers) { // All towers targeting this nightmare should reset their target if (t.Target == nightmare) { t.Target = null; } } // All projectiles targeting this nightmare should be removed for (int index = projectiles.Count - 1; index >= 0; index--) { p = projectiles[index]; // If projectile is targeting this nightmare if (p.Target == nightmare) { projectiles.Remove(p); } } player.Wallet += nightmare.Bounty; nightmares.Remove(nightmare); }