Game Development Reference
In-Depth Information
private void UpdateCollisions()
{
_bulletManager.UpdatePlayerCollision(_playerCharacter);
For the enemies to use their newfound shooting powers, they need access to the
BulletManager
class. This can be passed into the
EnemyManager
and into
each individual enemy from there. Here it's passed into the
EnemyManager
from the
Level
class constructor.
public Level(Input input, TextureManager textureManager, Persistant
GameData gameData)
{
_input
¼
input;
_gameData
¼
gameData;
_textureManager
¼
textureManager;
_effectsManager
¼
new EffectsManager(_textureManager);
_enemyManager
¼
new EnemyManager(_textureManager, _effectsManager,
_bulletManager, -1300);
In the following code, the
EnemyManager
stores a reference to the
Bullet-
Manager
and uses it when constructing enemies.
BulletManager _bulletManager;
public EnemyManager(TextureManager textureManager, EffectsManager
effectsManager, BulletManager bulletManger, int leftBound)
{
_bulletManager
¼
bulletManger;
// Code omitted
private Enemy CreateEnemyFromDef(EnemyDef definition)
{
Enemy enemy
¼
new Enemy(_textureManager, _effectsManager,
_bulletManager);
The enemies now have the
BulletManager
and with it the power to start
shooting bullets. The question now is when should the enemies shoot? They
can't shoot every frame or the game would be far too hard. The enemies
shouldn't all fire at the same time or it will be far too difficult. The trick is to set
the firing times randomly for each enemy.
public double MaxTimeToShoot { get; set; }
Search WWH ::
Custom Search