ComputerTerminal.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. class ComputerTerminal
  10. {
  11. #region Declarations
  12. private Sprite activeSprite;
  13. private Sprite inactiveSprite;
  14. public Vector2 MapLocation;
  15. public bool Active = true;
  16. public float LastSpawnCounter = 0;
  17. public float minSpawnTime = 6.0f;
  18. #endregion
  19. #region Constructor
  20. public ComputerTerminal(
  21. Sprite activeSprite,
  22. Sprite inactiveSprite,
  23. Vector2 mapLocation)
  24. {
  25. MapLocation = mapLocation;
  26. this.activeSprite = activeSprite;
  27. this.inactiveSprite = inactiveSprite;
  28. }
  29. #endregion
  30. #region Public Methods
  31. public bool IsCircleColliding(Vector2 otherCenter, float radius)
  32. {
  33. if (!Active)
  34. {
  35. return false;
  36. }
  37. return activeSprite.IsCircleColliding(otherCenter, radius);
  38. }
  39. public void Deactivate()
  40. {
  41. Active = false;
  42. }
  43. public void Update(GameTime gameTime)
  44. {
  45. if (Active)
  46. {
  47. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
  48. LastSpawnCounter += elapsed;
  49. if (LastSpawnCounter > minSpawnTime)
  50. {
  51. if (Vector2.Distance(activeSprite.WorldCenter,
  52. Player.BaseSprite.WorldCenter) > 128)
  53. {
  54. if (EnemyManager.Enemies.Count <
  55. EnemyManager.MaxActiveEnemies)
  56. {
  57. EnemyManager.AddEnemy(MapLocation);
  58. LastSpawnCounter = 0;
  59. }
  60. }
  61. }
  62. activeSprite.Update(gameTime);
  63. }
  64. else
  65. {
  66. inactiveSprite.Update(gameTime);
  67. }
  68. }
  69. public void Draw(SpriteBatch spriteBatch)
  70. {
  71. if (Active)
  72. {
  73. activeSprite.Draw(spriteBatch);
  74. }
  75. else
  76. {
  77. inactiveSprite.Draw(spriteBatch);
  78. }
  79. }
  80. #endregion
  81. }
  82. }