2
0

Constants.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 XNAPacMan {
  8. /// <summary>
  9. /// This class provides global access to important game constants; what fruits appear on what levels,
  10. /// relative speeds of everything, timers, etc. Centralizing this data here makes it easy to change
  11. /// the game settings. It also relieves the data-heavy ghost and gameloop classes from a LOT of definitions.
  12. /// </summary>
  13. static class Constants {
  14. // Dispersion tiles for each ghost
  15. public static readonly List<Point> scatterTilesBlinky = new List<Point> { new Point(21, 1), new Point(26, 1),
  16. new Point(26, 5), new Point(21, 5)
  17. };
  18. public static readonly List<Point> scatterTilesPinky = new List<Point> { new Point(1, 1), new Point(6, 1),
  19. new Point(6, 5), new Point(1, 5)
  20. };
  21. public static readonly List<Point> scatterTilesClyde = new List<Point> { new Point(6, 23), new Point(9, 23),
  22. new Point(9, 26), new Point(12, 26),
  23. new Point(12, 29), new Point(1, 29),
  24. new Point(1, 26), new Point(6, 26)
  25. };
  26. public static readonly List<Point> scatterTilesInky = new List<Point> { new Point(18, 23), new Point(21, 23),
  27. new Point(21, 26), new Point(26, 26),
  28. new Point(26, 29), new Point(15, 29),
  29. new Point(15, 26), new Point(18, 26)
  30. };
  31. public static List<Point> scatterTiles(Ghosts identity) {
  32. switch (identity) {
  33. case Ghosts.Blinky:
  34. return scatterTilesBlinky;
  35. case Ghosts.Clyde:
  36. return scatterTilesClyde;
  37. case Ghosts.Inky:
  38. return scatterTilesInky;
  39. case Ghosts.Pinky:
  40. return scatterTilesPinky;
  41. default:
  42. throw new ArgumentException();
  43. }
  44. }
  45. public static readonly Position startPositionBlinky = new Position { Tile = new Point(13, 11), DeltaPixel = new Point(8, 0) };
  46. public static readonly Position startPositionPinky = new Position { Tile = new Point(13, 14), DeltaPixel = new Point(8, 8) };
  47. public static readonly Position startPositionInky = new Position { Tile = new Point(11, 13), DeltaPixel = new Point(8, 8) };
  48. public static readonly Position startPositionClyde = new Position { Tile = new Point(15, 13), DeltaPixel = new Point(8, 8) };
  49. public static Position startPosition(Ghosts identity) {
  50. switch (identity) {
  51. case Ghosts.Blinky:
  52. return startPositionBlinky;
  53. case Ghosts.Pinky:
  54. return startPositionPinky;
  55. case Ghosts.Clyde:
  56. return startPositionClyde;
  57. case Ghosts.Inky:
  58. return startPositionInky;
  59. default:
  60. throw new ArgumentException();
  61. }
  62. }
  63. public static int Level = 0;
  64. public static int InitialJumps(Ghosts ghost, bool newLevel) {
  65. if (newLevel) {
  66. switch (ghost) {
  67. case Ghosts.Inky:
  68. return (int)MathHelper.Clamp((20 - Level) / 2, 0, 10);
  69. case Ghosts.Clyde:
  70. return InitialJumps(Ghosts.Inky, true) + 2;
  71. default:
  72. return 0;
  73. }
  74. }
  75. else {
  76. switch (ghost) {
  77. case Ghosts.Inky:
  78. return 1;
  79. case Ghosts.Clyde:
  80. return 2;
  81. default:
  82. return 0;
  83. }
  84. }
  85. }
  86. private static int[] cruiseElroyTimers_ = { 20, 30, 40, 40, 40, 50, 50, 50, 60, 60 };
  87. public static int CruiseElroyTimer() {
  88. if (Level >= 10) {
  89. return cruiseElroyTimers_[9];
  90. }
  91. else {
  92. return cruiseElroyTimers_[Level - 1];
  93. }
  94. }
  95. public static Color colors(Ghosts identity) {
  96. switch (identity) {
  97. case Ghosts.Blinky:
  98. return Color.Red;
  99. case Ghosts.Clyde:
  100. return Color.Orange;
  101. case Ghosts.Inky:
  102. return Color.LightSkyBlue;
  103. case Ghosts.Pinky:
  104. return Color.LightPink;
  105. default:
  106. throw new ArgumentException();
  107. }
  108. }
  109. private static int[] blueTimes_ = { 6, 6, 4, 3, 2, 6, 2, 2, 1, 5, 2, 1, 1, 3, 1, 1, 0, 1, 0, 0, 0 };
  110. public static int BlueTime() {
  111. return Level > blueTimes_.Length - 2 ? 0 : blueTimes_[Level - 1];
  112. }
  113. private static int[] bonusScores_ = { 100, 300, 500, 700, 700, 1000, 1000, 2000, 2000, 3000, 3000, 5000, 5000, 5000 };
  114. public static int BonusScores() {
  115. return Level > bonusScores_.Length - 2 ? 5000 : bonusScores_[Level - 1];
  116. }
  117. private static string[] bonusSprites_ = { "Cherry", "Strawberry", "Apple", "Bell", "Orange", "Pear", "Pretzel", "Bell", "Banana", "Key", "Key" };
  118. public static string BonusSprite() {
  119. return Level > bonusSprites_.Length - 2 ? "Key" : bonusSprites_[Level - 1];
  120. }
  121. private static int[] pacManSpeed_ = { 7, 9, 8, 8, 9 };
  122. public static int PacManSpeed() {
  123. if (5 <= Level && Level <= 20) {
  124. return pacManSpeed_[4];
  125. }
  126. else if (5 > Level) {
  127. return pacManSpeed_[Level - 1];
  128. }
  129. else {
  130. return 10;
  131. }
  132. }
  133. private static int[] ghostSpeed_ = { 13, 11, 12, 12 };
  134. public static int GhostSpeed() {
  135. return Level > 4 ? 11 : ghostSpeed_[Level - 1];
  136. }
  137. }
  138. }