Game Development Reference
In-Depth Information
used here and neither can forward iteration; if you were doing forward iteration
and removed a bullet, then the list would become shorter by one element, and
when the loop got to the end of the list, it would have an out of bounds error.
Reversing the iteration of the loop fixes this problem. The length of the list
doesn't matter; it will always head to 0.
The Render method is quite standard; it just renders out all of the bullets.
This BulletManager is best placed in the Level class. If you don't have a
using System.Drawing statement at the top of the Level.cs file then you will
need to add one before you can use the RectangleF class.
class Level
{
BulletManager _bulletManager ΒΌ new BulletManager(new RectangleF(-1300
/ 2, -750 / 2, 1300, 750));
The BulletManager is given a playing area. This is a little bigger than the
actual window size. This provides a buffer so that the bullets are totally off-screen
before they are destroyed. The BulletManager then needs to be added to the
Update and Render methods in the Level class.
public void Update(double elapsedTime)
{
UpdateCollisions();
_bulletManager.Update(elapsedTime);
// A little later in the code
public void Render(Renderer renderer)
{
_background.Render(renderer);
_backgroundLayer.Render(renderer);
_enemyList.ForEach(x = > x.Render(renderer));
_playerCharacter.Render(renderer);
_bulletManager.Render(renderer);
}
The BulletManager is rendered last so that bullets will be rendered on top of
everything. At this point, the BulletManager is fully integrated, but there's no
way to test it without giving the player a way to fire bullets. For this to happen,
 
Search WWH ::




Custom Search