levelSelectState.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. function LevelSelectState(levelPack) {
  2. LevelSelectState.superclass.constructor.apply(this);
  3. this.levelPack = levelPack;
  4. this.icons = [];
  5. this.labels = [];
  6. this.stars = [];
  7. this.backButton = null;
  8. this.walkButton = null;
  9. this.a10Logo = null;
  10. }
  11. extend(LevelSelectState, TrinState);
  12. LevelSelectState.prototype.update = function() {
  13. LevelSelectState.superclass.update.apply(this);
  14. for (var i = 0; i < this.labels.length; i++) {
  15. var label = this.labels[i];
  16. var sprite = this.icons[i];
  17. if (this.icons[i].isHovered()) {
  18. label.setStyle("font", 48, true, "#01A0C7");
  19. label.x = sprite.x - 15 * label.text.length;
  20. label.y = sprite.y;
  21. for (var j = 0; j < this.stars[i].length; j++) {
  22. var star = this.stars[i][j];
  23. star.switchAnimation("LSBigStar");
  24. star.reset(sprite.x + 27 * (j - 1), sprite.y + 18);
  25. if (j === 2) {
  26. star.x += 1;
  27. }
  28. }
  29. } else {
  30. label.setStyle("font", 32, true, "#FFFFFF");
  31. label.x = sprite.x - 10 * label.text.length;
  32. label.y = sprite.y;
  33. for (var j = 0; j < this.stars[i].length; j++) {
  34. var star = this.stars[i][j];
  35. star.switchAnimation("LSSmallStar");
  36. star.reset(sprite.x + 24 * (j - 1), sprite.y + 13);
  37. if (j === 0) {
  38. star.x += 2;
  39. }
  40. if (j === 1) {
  41. star.x += 1;
  42. }
  43. }
  44. }
  45. }
  46. };
  47. LevelSelectState.prototype.create = function() {
  48. LevelSelectState.superclass.create.apply(this);
  49. var back = new TrinSprite();
  50. back.addAnimationFromCache("LevelSelectBack");
  51. var levels = this.levelPack.levels;
  52. var levelsData = Global.prototype.levels[this.levelPack.name];
  53. for (var i = 0; i < levels.length; i++) {
  54. var row = Math.floor(i / 5);
  55. var col = i % 5;
  56. var sprite;
  57. var stars;
  58. if (levelsData[i] === -1) {
  59. sprite = new TrinSprite();
  60. sprite.addAnimationFromCache("LockedStage");
  61. } else {
  62. var levelFunction = function() {
  63. _TrinGame.switchState(
  64. new PlayState(arguments.callee.levelPack, arguments.callee.level));
  65. };
  66. levelFunction.levelPack = this.levelPack;
  67. levelFunction.level = i;
  68. sprite = new TrinButton(levelFunction, "bStage", false);
  69. stars = [];
  70. for (var j = 0; j < levelsData[i]; j++) {
  71. var star = new TrinSprite();
  72. star.addAnimationFromCache("LSSmallStar");
  73. star.addAnimationFromCache("LSBigStar", false);
  74. star.orign.x = star.width / 2;
  75. stars[j] = star;
  76. }
  77. }
  78. sprite.orign.x = sprite.width / 2;
  79. sprite.orign.y = sprite.height / 2;
  80. sprite.reset(80 + col * 120, 300 + row * 140);
  81. this.icons[i] = sprite;
  82. if (levelsData[i] !== -1) {
  83. var label = new TrinText(i + 1);
  84. label.setStyle("font", 32, true, "#FFFFFF");
  85. label.x = sprite.x - 10 * label.text.length;
  86. label.y = sprite.y;
  87. label.baseLine = "alphabetic";
  88. this.labels[i] = label;
  89. this.stars[i] = stars;
  90. for (j = 0; j < stars.length; j++) {
  91. var star = stars[j];
  92. star.orign.x = star.width / 2;
  93. star.reset(sprite.x + 24 * (j - 1), sprite.y + 13);
  94. if (j === 0) {
  95. star.x += 2;
  96. }
  97. }
  98. }
  99. }
  100. var backButton = new TrinButton(function() {
  101. _TrinGame.switchState(new LevelPackSelectState());
  102. }, "bBack", false);
  103. backButton.orign.x = backButton.width;
  104. backButton.orign.y = backButton.height;
  105. backButton.reset(632, _TrinGame.visibleArea.bottom - 8);
  106. this.backButton = backButton;
  107. var walkButton = new TrinButton(function() {
  108. // Play68.goHome();
  109. //window.open(TrinAssetLoader.prototype.LOADED_JSON["links"].walkthrought, "_blank");
  110. }, "bWalk", true);
  111. walkButton.orign.x = walkButton.width;
  112. walkButton.orign.y = walkButton.height + 20;
  113. walkButton.reset(backButton.x - backButton.width - 8, backButton.y);
  114. this.walkButton = walkButton;
  115. this.add(back);
  116. for (i = 0; i < this.icons.length; i++) {
  117. this.add(this.icons[i]);
  118. if (this.labels.length > i) {
  119. this.add(this.labels[i]);
  120. for (j = 0; j < this.stars[i].length; j++) {
  121. this.add(this.stars[i][j]);
  122. }
  123. }
  124. }
  125. var a10Logo = new TrinButton(function() {
  126. _TrinGame.SPIL_LOGO.action();
  127. }, "A10Logo", true);
  128. a10Logo.orign.y = a10Logo.height;
  129. a10Logo.reset(8, _TrinGame.visibleArea.bottom - 8);
  130. this.a10Logo = a10Logo;
  131. this.add(backButton);
  132. this.add(walkButton);
  133. this.add(a10Logo);
  134. };
  135. LevelSelectState.prototype.resized = function(){
  136. this.backButton.y = this.walkButton.y = this.a10Logo.y = _TrinGame.visibleArea.bottom - 8;
  137. };