createjs_game.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.logo=new createjs.Bitmap("img/doudouIcon.png");
  53. this.logo.x = a / 2-130;
  54. this.logo.y = b / 2-150;
  55. this.progressText = new createjs.Text("\u8d44\u6e90\u52a0\u8f7d\u4e2d..", "bold 24px Arial", "black");
  56. this.progressText.x = a / 2;
  57. this.progressText.y = b / 2;
  58. this.progressText.textAlign = "center";
  59. this.progressText.textBaseline = "middle";
  60. this.addChild(this.logo);
  61. this.addChild(this.progressText);
  62. }
  63. ProgressBar.prototype = new createjs.Container;
  64. ProgressBar.prototype.completeCallback = function (a) {
  65. this.parent.removeChild(this);
  66. };
  67. ProgressBar.prototype.progressCallback = function (a) {
  68. //this.progress.graphics.r(0, 0, this.w * a.progress, this.h);
  69. this.progressText.text = "\u5df2\u52a0\u8f7d: " + parseInt(100 * a.progress) + "%";
  70. };
  71. ProgressBar.prototype.forQueue = function (a) {
  72. this.errorList = [];
  73. a.on("complete", this.completeCallback, this, !0);
  74. a.on("progress", this.progressCallback, this);
  75. a.on("error", function (a) {
  76. //alert("网速不给力,刷新一下吧!")
  77. }, null, !0);
  78. a.on("error", function (a) {
  79. this.errorList.push(a.item.src);
  80. }, this);
  81. };
  82. function RepeatedImgLayer(a, b, c, d) {
  83. this.initialize();
  84. d = a.width + d;
  85. b += d;
  86. this.graphics.bf(a).r(0, 0, b, a.height);
  87. this.setBounds(0, 0, b, a.height);
  88. this.animation = createjs.Tween.get(this, {loop:!0}).to({x:-d}, d / c * 1000);
  89. this.do_cache();
  90. }
  91. RepeatedImgLayer.prototype = new createjs.Shape;
  92. RepeatedImgLayer.prototype.setPaused = function (a) {
  93. this.animation.setPaused(a);
  94. };
  95. function ImageButton(a, b, c) {
  96. this.initialize();
  97. a = new createjs.Bitmap(queue.getResult(a));
  98. 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);
  99. this.addChild(a);
  100. c && (c = this.getBounds(), this.regX = c.width / 2, this.regY = c.height / 2);
  101. this.on("mousedown", function () {
  102. this._addFilter(new createjs.ColorMatrixFilter((new createjs.ColorMatrix).adjustBrightness(-80)), "mouse");
  103. }, this);
  104. this.on("pressup", function () {
  105. this._removeFilter("mouse");
  106. }, this);
  107. }
  108. ImageButton.prototype = new createjs.Container;
  109. ImageButton.prototype._addFilter = function (a, b) {
  110. a.tag = b;
  111. if (this.filters) {
  112. for (var c in this.filters) {
  113. if (this.filters[c].tag == b) {
  114. return;
  115. }
  116. }
  117. this.filters.push(a);
  118. } else {
  119. this.filters = [a];
  120. }
  121. this.do_cache();
  122. };
  123. ImageButton.prototype._removeFilter = function (a) {
  124. if (this.filters) {
  125. var b = [], c;
  126. for (c in this.filters) {
  127. var d = this.filters[c];
  128. a != d.tag && b.push(d);
  129. }
  130. this.filters = b;
  131. this.do_cache();
  132. }
  133. };
  134. ImageButton.prototype.setEnabled = function (a) {
  135. (this.mouseEnabled = a) ? this._removeFilter("disable") : (a = new createjs.ColorMatrixFilter((new createjs.ColorMatrix).adjustBrightness(-80).adjustSaturation(-100)), this._addFilter(a, "disable"));
  136. };
  137. function loadFollowRes() {
  138. USE_NATIVE_SHARE || queue.loadManifest({path:BASE_RES_DIR + "img/", manifest:[{src:"follow_anim.png", id:"follow"}]}, !1);
  139. }
  140. function addFollowAnim(a) {
  141. if (!USE_NATIVE_SHARE) {
  142. var b = new createjs.SpriteSheet({framerate:10, images:[queue.getResult("follow")], frames:{width:170, height:150}, animations:{show:[0, 4, !0]}});
  143. g_followAnim = new createjs.Sprite(b);
  144. g_followAnim.y = H;
  145. g_followAnim.name = "follow";
  146. g_followAnim.on("click", function () {
  147. window.open(FOLLOW_URL, "follow");
  148. });
  149. g_followAnim.visible = !1;
  150. void 0 == a ? stage.addChild(g_followAnim) : a.addChild(g_followAnim);
  151. }
  152. }
  153. function setFollowParent(a) {
  154. USE_NATIVE_SHARE || (g_followAnim.parent.removeChild(g_followAnim), a.addChild(g_followAnim));
  155. }
  156. function setFollowAnim(a) {
  157. if (!USE_NATIVE_SHARE && IS_REFFER) {
  158. var b = g_followAnim.getBounds();
  159. 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 () {
  160. g_followAnim.stop();
  161. });
  162. }
  163. }
  164. USE_NATIVE_SOUND ? createjs.Sound.play = function (a) {
  165. window.open("qipa://sound/" + GID + "/" + a);
  166. } : IS_NATIVE_ANDROID && (createjs.Sound.play = function (a, b) {
  167. var c = queue.getResult("sound");
  168. c.currentTime = this.soundSprite[a];
  169. c.play();
  170. void 0 != b && !0 == b && (null != g_androidsoundtimer && (clearTimeout(g_androidsoundtimer), g_androidsoundtimer = null), g_androidsoundtimer = setTimeout(function () {
  171. createjs.Sound.play("silenttail");
  172. }, 1000));
  173. }, createjs.Sound.registMySound = function (a, b) {
  174. this.soundSprite || (this.soundSprite = {});
  175. this.soundSprite[a] = b;
  176. });
  177. function loadGameData(a) {
  178. }
  179. function zero_fill_hex(a, b) {
  180. for (var c = a.toString(16); c.length < b; ) {
  181. c = "0" + c;
  182. }
  183. return c;
  184. }
  185. function rgb2hex(a) {
  186. if ("#" == a.charAt(0)) {
  187. return a;
  188. }
  189. a = a.split(/\D+/);
  190. return "#" + zero_fill_hex(65536 * Number(a[1]) + 256 * Number(a[2]) + Number(a[3]), 6);
  191. }
  192. function hex2rgb(a) {
  193. var b = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  194. a = a.toLowerCase();
  195. var c = new RGBAcolor;
  196. if (a && b.test(a)) {
  197. if (4 === a.length) {
  198. for (var b = "#", d = 1; 4 > d; d += 1) {
  199. b += a.slice(d, d + 1).concat(a.slice(d, d + 1));
  200. }
  201. a = b;
  202. }
  203. b = [];
  204. b.push(parseInt("0x" + a.slice(1, 3)));
  205. c.r = parseInt("0x" + a.slice(1, 3));
  206. b.push(parseInt("0x" + a.slice(3, 5)));
  207. c.g = parseInt("0x" + a.slice(3, 5));
  208. b.push(parseInt("0x" + a.slice(5, 7)));
  209. c.b = parseInt("0x" + a.slice(5, 7));
  210. c.rgbastring = "RGB(" + b.join(",") + ")";
  211. return c;
  212. }
  213. return a;
  214. }
  215. function RGBAcolor() {
  216. this.a = this.A = this.b = this.B = this.g = this.G = this.r = this.R = 0;
  217. this.rgbastring = null;
  218. }
  219. createjs.DisplayObject.prototype.setAnchorPoint = function (a, b) {
  220. var c = this.getBounds();
  221. this.regX = c.width * a;
  222. this.regY = c.height * b;
  223. };
  224. createjs.Container.prototype.addCenterChild = function (a) {
  225. a.setAnchorPoint(0.5, 0.5);
  226. var b = this.getBounds();
  227. a.x = b.x + 0.5 * b.width;
  228. a.y = b.y + 0.5 * b.height;
  229. this.addChild(a);
  230. };