Game Development Reference
In-Depth Information
{
_input ¼ input;
_gameData ¼ gameData;
_textureManager ¼ textureManager;
_effectsManager ¼ new EffectsManager(_textureManager);
// code omitted
public void Update(double elapsedTime)
{
_effectsManager.Update(elapsedTime);
// code omitted
public void Render(Renderer renderer)
{
// Background, sprites and bullet code omitted
_effectsManager.Render(renderer);
renderer.Render();
}
The ExplosionManager is now hooked up and can be used to launch several
explosions at once. For the enemies to launch explosions when they die, they
need access to the manager, which can be passed into the constructor.
EffectsManager _effectsManager;
public Enemy(TextureManager textureManager, EffectsManager
effectsManager)
{
_effectsManager ¼ effectsManager;
The enemy can now set off an explosion when it dies.
private void OnDestroyed()
{
// Kill the enemy here.
_effectsManager.AddExplosion(_sprite.GetPosition());
}
In the Level.cs file, the EffectsManager needs to be passed into the Enemy
constructor. Once this is done, shooting the enemy a couple of times in the game
will cause an explosion when the enemy is destroyed.
Search WWH ::




Custom Search