2
0

ExplosionManager.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Collections.Generic;
  2. using Microsoft.Xna.Framework;
  3. using RockRainIphone.Core;
  4. namespace RockRainIphone
  5. {
  6. /// <summary>
  7. /// This is a game component that implements IUpdateable.
  8. /// </summary>
  9. public class ExplosionManager : Microsoft.Xna.Framework.DrawableGameComponent
  10. {
  11. protected List<ExplosionParticleSystem> explosions;
  12. public ExplosionManager(Game game)
  13. : base(game)
  14. {
  15. explosions = new List<ExplosionParticleSystem>();
  16. }
  17. /// <summary>
  18. /// Allows the game component to perform any initialization it needs to before starting
  19. /// to run. This is where it can query for any required services and load content.
  20. /// </summary>
  21. public override void Initialize()
  22. {
  23. // TODO: Add your initialization code here
  24. base.Initialize();
  25. }
  26. public void AddExplosion(Vector2 position)
  27. {
  28. ExplosionParticleSystem explosion = new ExplosionParticleSystem(Game, 1);
  29. explosion.AddParticles(position);
  30. explosions.Add(explosion);
  31. }
  32. /// <summary>
  33. /// Allows the game component to update itself.
  34. /// </summary>
  35. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  36. public override void Update(GameTime gameTime)
  37. {
  38. for (int i = 0; i < explosions.Count; i++)
  39. {
  40. if (!explosions[i].Active)
  41. {
  42. explosions.RemoveAt(i);
  43. i--;
  44. }
  45. else
  46. {
  47. explosions[i].Update(gameTime);
  48. }
  49. }
  50. base.Update(gameTime);
  51. }
  52. public override void Draw(GameTime gameTime)
  53. {
  54. for (int i = 0; i < explosions.Count; i++)
  55. {
  56. explosions[i].Draw(gameTime);
  57. }
  58. base.Draw(gameTime);
  59. }
  60. }
  61. }