createjs_game.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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("网速不给力,刷新一下吧!")
  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. window.open(FOLLOW_URL, "follow");
  145. });
  146. g_followAnim.visible = !1;
  147. void 0 == a ? stage.addChild(g_followAnim) : a.addChild(g_followAnim);
  148. }
  149. }
  150. function setFollowParent(a) {
  151. USE_NATIVE_SHARE || (g_followAnim.parent.removeChild(g_followAnim), a.addChild(g_followAnim));
  152. }
  153. function setFollowAnim(a) {
  154. if (!USE_NATIVE_SHARE && IS_REFFER) {
  155. var b = g_followAnim.getBounds();
  156. 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 () {
  157. g_followAnim.stop();
  158. });
  159. }
  160. }
  161. USE_NATIVE_SOUND ? createjs.Sound.play = function (a) {
  162. window.open("qipa://sound/" + GID + "/" + a);
  163. } : IS_NATIVE_ANDROID && (createjs.Sound.play = function (a, b) {
  164. var c = queue.getResult("sound");
  165. c.currentTime = this.soundSprite[a];
  166. c.play();
  167. void 0 != b && !0 == b && (null != g_androidsoundtimer && (clearTimeout(g_androidsoundtimer), g_androidsoundtimer = null), g_androidsoundtimer = setTimeout(function () {
  168. createjs.Sound.play("silenttail");
  169. }, 1000));
  170. }, createjs.Sound.registMySound = function (a, b) {
  171. this.soundSprite || (this.soundSprite = {});
  172. this.soundSprite[a] = b;
  173. });
  174. function loadGameData(a) {
  175. }
  176. function zero_fill_hex(a, b) {
  177. for (var c = a.toString(16); c.length < b; ) {
  178. c = "0" + c;
  179. }
  180. return c;
  181. }
  182. function rgb2hex(a) {
  183. if ("#" == a.charAt(0)) {
  184. return a;
  185. }
  186. a = a.split(/\D+/);
  187. return "#" + zero_fill_hex(65536 * Number(a[1]) + 256 * Number(a[2]) + Number(a[3]), 6);
  188. }
  189. function hex2rgb(a) {
  190. var b = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  191. a = a.toLowerCase();
  192. var c = new RGBAcolor;
  193. if (a && b.test(a)) {
  194. if (4 === a.length) {
  195. for (var b = "#", d = 1; 4 > d; d += 1) {
  196. b += a.slice(d, d + 1).concat(a.slice(d, d + 1));
  197. }
  198. a = b;
  199. }
  200. b = [];
  201. b.push(parseInt("0x" + a.slice(1, 3)));
  202. c.r = parseInt("0x" + a.slice(1, 3));
  203. b.push(parseInt("0x" + a.slice(3, 5)));
  204. c.g = parseInt("0x" + a.slice(3, 5));
  205. b.push(parseInt("0x" + a.slice(5, 7)));
  206. c.b = parseInt("0x" + a.slice(5, 7));
  207. c.rgbastring = "RGB(" + b.join(",") + ")";
  208. return c;
  209. }
  210. return a;
  211. }
  212. function RGBAcolor() {
  213. this.a = this.A = this.b = this.B = this.g = this.G = this.r = this.R = 0;
  214. this.rgbastring = null;
  215. }
  216. createjs.DisplayObject.prototype.setAnchorPoint = function (a, b) {
  217. var c = this.getBounds();
  218. this.regX = c.width * a;
  219. this.regY = c.height * b;
  220. };
  221. createjs.Container.prototype.addCenterChild = function (a) {
  222. a.setAnchorPoint(0.5, 0.5);
  223. var b = this.getBounds();
  224. a.x = b.x + 0.5 * b.width;
  225. a.y = b.y + 0.5 * b.height;
  226. this.addChild(a);
  227. };