/// <summary> /// Returns an instance of a usable player bullet. Prefers reusing an /// existing (dead) /// bullet over creating a new instance. /// </summary> /// <returns>A bullet ready to place into the world.</returns> Bullet CreatePlayerBullet() { Bullet b = null; for (int i = 0; i < playerBullets.Count; ++i) { if (playerBullets[i].IsAlive == false) { b = playerBullets[i]; break; } } if (b == null) { b = new Bullet(); playerBullets.Add(b); } b.IsAlive = true; return b; }
/// <summary> /// Returns an instance of a usable alien bullet. Prefers reusing an existing (dead) /// bullet over creating a new instance. /// </summary> /// <returns>A bullet ready to place into the world.</returns> Bullet CreateAlienBullet() { Bullet b = null; for (int i = 0; i < alienBullets.Count; ++i) { if (alienBullets[i].IsAlive == false) { b = alienBullets[i]; break; } } if (b == null) { b = new Bullet(); alienBullets.Add(b); } b.IsAlive = true; return b; }