EnemyManager.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. namespace Robot_Rampage
  8. {
  9. static class EnemyManager
  10. {
  11. #region Declarations
  12. public static List<Enemy> Enemies = new List<Enemy>();
  13. public static Texture2D enemyTexture;
  14. public static Rectangle enemyInitialFrame;
  15. public static int MaxActiveEnemies = 30;
  16. #endregion
  17. #region Initialization
  18. public static void Initialize(
  19. Texture2D texture,
  20. Rectangle initialFrame)
  21. {
  22. enemyTexture = texture;
  23. enemyInitialFrame = initialFrame;
  24. }
  25. #endregion
  26. #region Enemy Management
  27. public static void AddEnemy(Vector2 squareLocation)
  28. {
  29. int startX = (int)squareLocation.X;
  30. int startY = (int)squareLocation.Y;
  31. Rectangle squareRect =
  32. TileMap.SquareWorldRectangle(startX, startY);
  33. Enemy newEnemy = new Enemy(
  34. new Vector2(squareRect.X, squareRect.Y),
  35. enemyTexture,
  36. enemyInitialFrame);
  37. newEnemy.currentTargetSquare = squareLocation;
  38. Enemies.Add(newEnemy);
  39. }
  40. #endregion
  41. #region Update and Draw
  42. public static void Update(GameTime gameTime)
  43. {
  44. for (int x = Enemies.Count - 1; x >= 0; x--)
  45. {
  46. Enemies[x].Update(gameTime);
  47. if (Enemies[x].Destroyed)
  48. {
  49. Enemies.RemoveAt(x);
  50. }
  51. }
  52. }
  53. public static void Draw(SpriteBatch spriteBatch)
  54. {
  55. foreach (Enemy enemy in Enemies)
  56. {
  57. enemy.Draw(spriteBatch);
  58. }
  59. }
  60. #endregion
  61. }
  62. }