I have a boss that's supposed to continuously shoot five streams of bullets, each at a different angle. It starts off just fine, but doesn't seem to want to use its entire array of bullets. No matter how large I set the length of bulletList, the boss simply stops shooting after a couple of seconds, then pick up again shortly. Here's what I'm using to generate the pattern:
Vector3 direction = new Vector3(0.5f, -1, 0);
for (int r = 0; r < boss.gun.bulletList.Length; r++)
{
if (!boss.gun.bulletList[r].isActive)
{
boss.gun.bulletList[r].direction = direction;
boss.gun.bulletList[r].speed = boss.gun.BulletSpeedAdjustment;
boss.gun.bulletList[r].position = boss.position;
boss.gun.bulletList[r].isActive = true;
break;
}
}
direction = new Vector3(-0.5f, -1, 0);
//Repeat with four similar for loops, to place a bullet in each direction
It doesn't seem to matter if the bulletList length is 1000 or 100000. What could be the issue here?
EDIT: This is the code that removes a bullet, when it goes out of bounds. It is inside Bullet.Update()
if (position.X > 950 ||
position.X < -950 ||
position.Y > 570 ||
position.Y < -570)
isActive = false;
This is the code that removes a bullet on contact with the player ship:
for (int i = 0; i < boss.gun.bulletList.Length; i++)
{
if (boss.gun.bulletList[i].isActive)
{
boss.gun.bulletList[i].Update(timeDelta);
if (!ship.invincible)
{
bulletSphere.Center = boss.gun.bulletList[i].position;
if (bulletSphere.Intersects(shipSphere))
{
boss.gun.bulletList[i].isActive = false;
ship.health -= boss.gun.damage;
}
}
}
}
And just for safe measure, here's the code that draws the bullets:
for (int j = 0; j < boss.gun.bulletList.Length; j++)
{
if (boss.gun.bulletList[j].isActive)
{
Matrix bulletTransform = Matrix.CreateTranslation(boss.gun.bulletList[j].position);
DrawModel(boss.gun.bulletModel, bulletTransform, boss.gun.bulletTransforms);
}
}
EDIT: It would appear that a large number of bullets are getting "stuck" on the boss. That is, they draw at boss.position, and never move.
