createjs_game.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. var stage, W = 640, H = 960, IS_TOUCH, SCREEN_SHOW_ALL = !1, g_androidsoundtimer = null, g_followAnim = null;
  2. onload = function () {
  3. stage = new createjs.Stage("stage");
  4. if (IS_TOUCH = createjs.Touch.isSupported()) {
  5. createjs.Touch.enable(stage, !0);
  6. var a = new createjs.Shape;
  7. a.graphics.f("white").r(0, 0, W, H);
  8. stage.addChild(a);
  9. }
  10. createjs.Ticker.setFPS(60);
  11. setTimeout(setCanvas, 100);
  12. createjs.Ticker.on("tick", stage);
  13. loadResource();
  14. initBest();
  15. };
  16. onresize = setCanvas;
  17. function setCanvas() {
  18. var a = stage.canvas, b = window.innerWidth, c = window.innerHeight - 3;
  19. if (SCREEN_SHOW_ALL) {
  20. var d = c;
  21. b / c > W / H ? b = W * c / H : c = H * b / W;
  22. a.style.marginTop = (d - c) / 2 + "px";
  23. } else {
  24. d = W * c / H, b >= d ? (b = d, stage.x = 0) : stage.x = (b - d) / 2;
  25. }
  26. a.width = W;
  27. a.height = H;
  28. a.style.width = b + "px";
  29. a.style.height = c + "px";
  30. }
  31. createjs.DisplayObject.prototype.do_cache = function () {
  32. var a = this.getBounds();
  33. this.cache(a.x, a.y, a.width, a.height);
  34. };
  35. function showFPS() {
  36. var a = new createjs.Text("", "bold 24px Arial", "red");
  37. a.x = W;
  38. a.textAlign = "right";
  39. a.textBaseline = "top";
  40. stage.addChild(a);
  41. createjs.Ticker.on("tick", function () {
  42. a.text = "FPS:" + createjs.Ticker.getMeasuredFPS(10).toFixed(2);
  43. });
  44. }
  45. function ProgressBar(a, b) {
  46. this.initialize();
  47. this.w = a;
  48. this.h = b;
  49. this.progress = new createjs.Shape;
  50. this.progress.graphics.s("black").r(0, 0, a, b).es();
  51. this.progress.graphics.lf(["red", "yellow", "blue"], [0, 0.5, 1], 0, 0, a, 0);
  52. this.progressText = new createjs.Text("\u8d44\u6e90\u52a0\u8f7d\u4e2d..", "bold 24px Arial", "black");
  53. this.progressText.x = a / 2;
  54. this.progressText.y = b / 2;
  55. this.progressText.textAlign = "center";
  56. this.progressText.textBaseline = "middle";
  57. this.addChild(this.progress);
  58. this.addChild(this.progressText);
  59. }
  60. ProgressBar.prototype = new createjs.Container;
  61. ProgressBar.prototype.completeCallback = function (a) {
  62. this.parent.removeChild(this);
  63. };
  64. ProgressBar.prototype.progressCallback = function (a) {
  65. this.progress.graphics.r(0, 0, this.w * a.progress, this.h);
  66. this.progressText.text = "\u5df2\u52a0\u8f7d: " + parseInt(100 * a.progress) + "%";
  67. };
  68. ProgressBar.prototype.forQueue = function (a) {
  69. this.errorList = [];
  70. a.on("complete", this.completeCallback, this, !0);
  71. a.on("progress", this.progressCallback, this);
  72. a.on("error", function (a) {
  73. alert("\ufffd\ufffd\ufffd\u0672\ufffd\ufffd\ufffdf\ufffd\ufffd\u02e2\ufffd\ufffd\u04bb\ufffd\xb0\ufffd!");
  74. }, null, !0);
  75. a.on("error", function (a) {
  76. this.errorList.push(a.item.src);
  77. }, this);
  78. };
  79. function RepeatedImgLayer(a, b, c, d) {
  80. this.initialize();
  81. d = a.width + d;
  82. b += d;
  83. this.graphics.bf(a).r(0, 0, b, a.height);
  84. this.setBounds(0, 0, b, a.height);
  85. this.animation = createjs.Tween.get(this, {loop:!0}).to({x:-d}, d / c * 1000);
  86. this.do_cache();
  87. }
  88. RepeatedImgLayer.prototype = new createjs.Shape;
  89. RepeatedImgLayer.prototype.setPaused = function (a) {
  90. this.animation.setPaused(a);
  91. };
  92. function ImageButton(a, b, c) {
  93. this.initialize();
  94. a = new createjs.Bitmap(queue.getResult(a));
  95. b && (b = new createjs.Bitmap(queue.getResult(b)), this.addChild(b), a.x = (b.image.width - a.image.width) / 2, a.y = (b.image.height - a.image.height) / 2);
  96. this.addChild(a);
  97. c && (c = this.getBounds(), this.regX = c.width / 2, this.regY = c.height / 2);
  98. this.on("mousedown", function () {
  99. this._addFilter(new createjs.ColorMatrixFilter((new createjs.ColorMatrix).adjustBrightness(-80)), "mouse");
  100. }, this);
  101. this.on("pressup", function () {
  102. this._removeFilter("mouse");
  103. }, this);
  104. }
  105. ImageButton.prototype = new createjs.Container;
  106. ImageButton.prototype._addFilter = function (a, b) {
  107. a.tag = b;
  108. if (this.filters) {
  109. for (var c in this.filters) {
  110. if (this.filters[c].tag == b) {
  111. return;
  112. }
  113. }
  114. this.filters.push(a);
  115. } else {
  116. this.filters = [a];
  117. }
  118. this.do_cache();
  119. };
  120. ImageButton.prototype._removeFilter = function (a) {
  121. if (this.filters) {
  122. var b = [], c;
  123. for (c in this.filters) {
  124. var d = this.filters[c];
  125. a != d.tag && b.push(d);
  126. }
  127. this.filters = b;
  128. this.do_cache();
  129. }
  130. };
  131. ImageButton.prototype.setEnabled = function (a) {
  132. (this.mouseEnabled = a) ? this._removeFilter("disable") : (a = new createjs.ColorMatrixFilter((new createjs.ColorMatrix).adjustBrightness(-80).adjustSaturation(-100)), this._addFilter(a, "disable"));
  133. };
  134. function loadFollowRes() {
  135. USE_NATIVE_SHARE || queue.loadManifest({path:BASE_RES_DIR + "img/", manifest:[{src:"follow_anim.png", id:"follow"}]}, !1);
  136. }
  137. function addFollowAnim(a) {
  138. if (!USE_NATIVE_SHARE) {
  139. var b = new createjs.SpriteSheet({framerate:10, images:[queue.getResult("follow")], frames:{width:170, height:150}, animations:{show:[0, 4, !0]}});
  140. g_followAnim = new createjs.Sprite(b);
  141. g_followAnim.y = H;
  142. g_followAnim.name = "follow";
  143. g_followAnim.on("click", function () {
  144. });
  145. g_followAnim.visible = !1;
  146. void 0 == a ? stage.addChild(g_followAnim) : a.addChild(g_followAnim);
  147. }
  148. }
  149. function setFollowParent(a) {
  150. USE_NATIVE_SHARE || (g_followAnim.parent.removeChild(g_followAnim), a.addChild(g_followAnim));
  151. }
  152. function setFollowAnim(a) {
  153. if (!USE_NATIVE_SHARE && IS_REFFER) {
  154. var b = g_followAnim.getBounds();
  155. a ? (g_followAnim.play(), createjs.Tween.get(g_followAnim).to({regX:b.width, regY:0, visible:!0}).to({regX:0, regY:b.height}, 500)) : createjs.Tween.get(g_followAnim).to({regX:b.width, regY:0}, 500).to({visible:!1}).call(function () {
  156. g_followAnim.stop();
  157. });
  158. }
  159. }
  160. function loadGameData(a) {
  161. }
  162. function zero_fill_hex(a, b) {
  163. for (var c = a.toString(16); c.length < b; ) {
  164. c = "0" + c;
  165. }
  166. return c;
  167. }
  168. function rgb2hex(a) {
  169. if ("#" == a.charAt(0)) {
  170. return a;
  171. }
  172. a = a.split(/\D+/);
  173. return "#" + zero_fill_hex(65536 * Number(a[1]) + 256 * Number(a[2]) + Number(a[3]), 6);
  174. }
  175. function hex2rgb(a) {
  176. var b = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  177. a = a.toLowerCase();
  178. var c = new RGBAcolor;
  179. if (a && b.test(a)) {
  180. if (4 === a.length) {
  181. for (var b = "#", d = 1; 4 > d; d += 1) {
  182. b += a.slice(d, d + 1).concat(a.slice(d, d + 1));
  183. }
  184. a = b;
  185. }
  186. b = [];
  187. b.push(parseInt("0x" + a.slice(1, 3)));
  188. c.r = parseInt("0x" + a.slice(1, 3));
  189. b.push(parseInt("0x" + a.slice(3, 5)));
  190. c.g = parseInt("0x" + a.slice(3, 5));
  191. b.push(parseInt("0x" + a.slice(5, 7)));
  192. c.b = parseInt("0x" + a.slice(5, 7));
  193. c.rgbastring = "RGB(" + b.join(",") + ")";
  194. return c;
  195. }
  196. return a;
  197. }
  198. function RGBAcolor() {
  199. this.a = this.A = this.b = this.B = this.g = this.G = this.r = this.R = 0;
  200. this.rgbastring = null;
  201. }
  202. createjs.DisplayObject.prototype.setAnchorPoint = function (a, b) {
  203. var c = this.getBounds();
  204. this.regX = c.width * a;
  205. this.regY = c.height * b;
  206. };
  207. createjs.Container.prototype.addCenterChild = function (a) {
  208. a.setAnchorPoint(0.5, 0.5);
  209. var b = this.getBounds();
  210. a.x = b.x + 0.5 * b.width;
  211. a.y = b.y + 0.5 * b.height;
  212. this.addChild(a);
  213. };