// take an inactive bullet from the pool and add it to the screen public static void AddBullet(GameSprite source, bool up) { // for each bullet for (int i = 0; i < m_Bullets.Length; i++) { // is this bullet inactive? if (!m_Bullets[i].IsActive) { // set bullet's direction m_Bullets[i].MoveUp = up; // set bullet's position, based on originator Vector2 pos = Vector2.Zero; pos.X = source.Location.X + source.TextureRect.Width / 2; pos.X -= m_Bullets[i].TextureRect.Width / 2; pos.Y = source.Location.Y + source.TextureRect.Height / 2; pos.Y -= m_Bullets[i].TextureRect.Height / 2; // add bullet to the screen m_Bullets[i].Init(); m_Bullets[i].Location = pos; m_Bullets[i].IsActive = true; // if this bullet came from a player, remember // who shot it so that they will get credit if it // hits an enemy if (source.GetType() == typeof(Player)) { m_Bullets[i].Shooter = (Player)source; } // we're done, exit the loop break; } } }