PlayerStatus.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //---------------------------------------------------------------------------------
  2. // Ported to the Atomic Game Engine
  3. // Originally written for XNA by Michael Hoffman
  4. // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
  5. //----------------------------------------------------------------------------------
  6. using AtomicEngine;
  7. using System.IO;
  8. namespace AtomicBlaster
  9. {
  10. static class PlayerStatus
  11. {
  12. // amount of time it takes, in seconds, for a multiplier to expire.
  13. private const float multiplierExpiryTime = 0.8f;
  14. private const int maxMultiplier = 20;
  15. public static int Lives { get; private set; }
  16. public static int Score { get; private set; }
  17. public static int Multiplier { get; private set; }
  18. public static bool IsGameOver { get { return Lives == 0; } }
  19. private static float multiplierTimeLeft; // time until the current multiplier expires
  20. private static int scoreForExtraLife; // score required to gain an extra life
  21. // Static constructor
  22. static PlayerStatus()
  23. {
  24. Reset();
  25. }
  26. public static void Reset()
  27. {
  28. Score = 0;
  29. Multiplier = 1;
  30. Lives = 4;
  31. scoreForExtraLife = 2000;
  32. multiplierTimeLeft = 0;
  33. }
  34. public static void Update()
  35. {
  36. if (Multiplier > 1)
  37. {
  38. // update the multiplier timer
  39. if ((multiplierTimeLeft -= (float)GameRoot.ElapsedTime) <= 0)
  40. {
  41. multiplierTimeLeft = multiplierExpiryTime;
  42. ResetMultiplier();
  43. }
  44. }
  45. }
  46. public static void AddPoints(int basePoints)
  47. {
  48. if (PlayerShip.Instance.IsDead)
  49. return;
  50. Score += basePoints * Multiplier;
  51. while (Score >= scoreForExtraLife)
  52. {
  53. scoreForExtraLife += 2000;
  54. Lives++;
  55. }
  56. }
  57. public static void IncreaseMultiplier()
  58. {
  59. if (PlayerShip.Instance.IsDead)
  60. return;
  61. multiplierTimeLeft = multiplierExpiryTime;
  62. if (Multiplier < maxMultiplier)
  63. Multiplier++;
  64. }
  65. public static void ResetMultiplier()
  66. {
  67. Multiplier = 1;
  68. }
  69. public static void RemoveLife()
  70. {
  71. Lives--;
  72. }
  73. }
  74. }