Game Development Reference
In-Depth Information
public void UpdateBulletList(List < Bullet > bulletList, double
elapsedTime)
{
bulletList.ForEach(x = > x.Update(elapsedTime));
CheckOutOfBounds(_bullets);
RemoveDeadBullets(bulletList);
}
private void CheckOutOfBounds(List < Bullet > bulletList)
{
foreach (Bullet bullet in bulletList)
{
if (!bullet.GetBoundingBox().IntersectsWith(_bounds))
{
bullet.Dead ¼ true;
}
}
}
private void RemoveDeadBullets(List < Bullet > bulletList)
{
for (int i ¼ bulletList.Count - 1; i > = 0; i-)
{
if (bulletList[i].Dead)
{
bulletList.RemoveAt(i);
}
}
}
internal void Render(Renderer renderer)
{
_bullets.ForEach(x = > x.Render(renderer));
_enemyBullets.ForEach(x = > x.Render(renderer));
}
The above code introduces a second list for enemy bullets; it now requires a
function that will let the enemy shoot bullets and a function to check if any of
them hit the player.
public void EnemyShoot(Bullet bullet)
{
Search WWH ::




Custom Search