main.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. var g_queue, qp_a, qp_b = [], qp_c = 1000, qp_d = 500, qp_e = !0, GAME_READY = 1, GAME_PLAY = 2, GAME_FAIL = -2, GAME_OVER = -1, GAME_START = -10, GAMESTATUS = GAME_START;
  2. function loadResource() {
  3. SCREEN_SHOW_ALL = !0;
  4. var a = new ProgressBar(0.8 * W, 40);
  5. a.regX = a.w / 2;
  6. a.regY = a.h / 2;
  7. a.x = W / 2;
  8. a.y = H / 2;
  9. stage.addChild(a);
  10. queue = new createjs.LoadQueue(!1);
  11. queue.setMaxConnections(30);
  12. loadGameData();
  13. queue.on("complete", qp_f, null, !0);
  14. queue.loadManifest({path:RES_DIR + "img/", manifest:[{src:"cloud1.png", id:"cloud1"}, {src:"cloud2.png", id:"cloud2"}, {src:"cloud3.png", id:"cloud3"}, {src:"cloud4.png", id:"cloud4"}, {src:"welcome.png", id:"welcome"}, {src:"logo.png", id:"logo"}, {src:"tag.png", id:"btnframe"}, {src:"start.png", id:"startbtnlabel"}, {src:"top.png", id:"topbtnlabel"}, {src:"share.png", id:"sharebutton"}, {src:"game_over.png", id:"gameoverbanner"}, {src:"score.png", id:"scorelabel"}, {src:"line.png", id:"line"}, {src:"green.png", id:"ballgreen"}, {src:"blue.png", id:"ballblue"}, {src:"red.png", id:"ballred"}]}, !1);
  15. a.forQueue(queue);
  16. queue.load();
  17. }
  18. function qp_f(a) {
  19. a = new Qp_g;
  20. stage.addChild(a);
  21. createjs.Ticker.on("tick", a.update, a);
  22. qp_a = new Qp_h;
  23. stage.addChild(qp_a);
  24. }
  25. function qp_i() {
  26. qp_a.startGame();
  27. }
  28. function qp_j() {
  29. //showTop();
  30. goHome();
  31. }
  32. function qp_k() {
  33. dp_share();
  34. }
  35. function Qp_g() {
  36. this.initialize();
  37. var a = new createjs.Shape;
  38. a.graphics.lf(["#88c3d9", "#9ddcf2"], [0, 1], 0, 0, 0, H).r(0, 0, W, H);
  39. this.addChild(a);
  40. for (a = this.nextCloud = 0; 3 > a; a++) {
  41. this.update();
  42. }
  43. }
  44. Qp_g.prototype = new createjs.Container;
  45. Qp_g.prototype.update = function (a) {
  46. a && (this.nextCloud -= a.delta / 1000);
  47. if (0 >= this.nextCloud) {
  48. var c = parseInt(4 * Math.random()) + 1, b = new createjs.Bitmap(queue.getResult("cloud" + c));
  49. b.setAnchorPoint(0.5, 0.5);
  50. b.y = Math.random() * H * 0.6;
  51. a ? (b.x = -b.image.width / 2, this.nextCloud += 5 * Math.random() + 5) : b.x = Math.random() * W;
  52. a = W + b.image.width / 2;
  53. createjs.Tween.get(b).to({x:a}, (a - b.x) * c * 10).call(function () {
  54. this.parent.removeChild(this);
  55. });
  56. this.addChild(b);
  57. }
  58. };
  59. function Qp_h() {
  60. this.initialize();
  61. this.menuLayer = new Qp_l;
  62. this.gameplayinglayer = new Qp_m;
  63. this.gameplayinglayer.visible = !1;
  64. this.addChild(this.menuLayer, this.gameplayinglayer);
  65. }
  66. Qp_h.prototype = new createjs.Container;
  67. Qp_h.prototype.gameover = function () {
  68. GAMESTATUS != GAME_OVER && (GAMESTATUS = GAME_OVER, createjs.Ticker.removeEventListener("tick", window.update), this.gameplayinglayer.visible = !1, onNewScore(score), this.menuLayer.gameover.buttonactions(), this.menuLayer.gameover.refresh(), this.menuLayer.visible = !0);
  69. };
  70. Qp_h.prototype.startGame = function () {
  71. GAMESTATUS = GAME_START;
  72. record_flag = !1;
  73. qp_b = [];
  74. score = 0;
  75. this.menuLayer.visible = !1;
  76. if (!1 == qp_e) {
  77. this.removeChild(a), this.gameplayinglayer.doReset(), this.gameplayinglayer.visible = !0, createjs.Ticker.addEventListener("tick", window.update);
  78. } else {
  79. qp_e = !1;
  80. var a = new createjs.Text("黑线下点猪头托飞它", "bold 60px Arial", "#ff9d36");
  81. a.stroke = "white";
  82. a.textBaseline = "middle";
  83. a.regX = a.getBounds().width / 2;
  84. a.regY = a.getBounds().height / 2;
  85. a.scaleX = 2;
  86. a.scaleY = 2;
  87. createjs.Tween.get(a).to({scaleX:1, scaleY:1}, 200);
  88. createjs.Tween.get(a).to({alpha:0.6}, 200).to({alpha:1}, 200).to({alpha:0.6}, 200).to({alpha:1}, 200);
  89. a.x = 320;
  90. a.y = 720;
  91. this.addChild(a);
  92. setTimeout(function () {
  93. qp_a.removeChild(a);
  94. qp_a.gameplayinglayer.doReset();
  95. qp_a.gameplayinglayer.visible = !0;
  96. createjs.Ticker.addEventListener("tick", window.update);
  97. }, 1500);
  98. }
  99. };
  100. function Qp_n(a, c, b, d, e) {
  101. this.initialize();
  102. c = new createjs.Bitmap(queue.getResult(c));
  103. c.setAnchorPoint(0.5, 0.5);
  104. a && (a = new createjs.Bitmap(queue.getResult(a)), a.setAnchorPoint(0.5, 0.5), this.addChild(a));
  105. this.addChild(c);
  106. this.do_cache();
  107. this.x = d;
  108. this.y = e;
  109. this.on("click", b);
  110. }
  111. Qp_n.prototype = new createjs.Container;
  112. function Qp_o(a, c, b, d) {
  113. this.initialize(queue.getResult(a));
  114. this.setAnchorPoint(0.5, 0.5);
  115. this.x = c;
  116. this.y = b;
  117. if (d) {
  118. this.on("click", d);
  119. }
  120. }
  121. Qp_o.prototype = new createjs.Bitmap;
  122. function Qp_p() {
  123. this.initialize();
  124. this.addChild(new Qp_o("gameoverbanner", 320, 350));
  125. this.sharebutton = new createjs.Bitmap(queue.getResult("sharebutton"));
  126. this.sharebutton.x = 320;
  127. this.sharebutton.y = 1200;
  128. this.sharebutton.regX = this.sharebutton.getBounds().width / 2;
  129. this.sharebutton.regY = this.sharebutton.getBounds().height / 2;
  130. this.sharebutton.on("mousedown", qp_k, this.sharebutton);
  131. this.addChild(this.sharebutton);
  132. this.scoreText = new createjs.Text(score, "bold 60px Arial", "#ff9d36");
  133. this.scoreText.stroke = "white";
  134. this.scoreText.textBaseline = "middle";
  135. this.scoreText.x = 420;
  136. this.scoreText.y = 330;
  137. this.addChild(this.scoreText);
  138. this.bestscoreText = new createjs.Text(best, "bold 60px Arial", "#ff9d36");
  139. this.bestscoreText.stroke = "white";
  140. this.bestscoreText.textBaseline = "middle";
  141. this.bestscoreText.x = 420;
  142. this.bestscoreText.y = 530;
  143. this.addChild(this.bestscoreText);
  144. }
  145. Qp_p.prototype = new createjs.Container;
  146. Qp_p.prototype.buttonactions = function () {
  147. var a = qp_a.menuLayer.start;
  148. a.y = 1200;
  149. createjs.Tween.get(a).to({y:720}, 200);
  150. a = qp_a.menuLayer.top;
  151. a.y = 1200;
  152. createjs.Tween.get(a).to({y:1200}, 150).to({y:720}, 200);
  153. createjs.Tween.get(this.sharebutton).to({y:1200}, 350).to({y:880}, 200);
  154. };
  155. Qp_p.prototype.refresh = function () {
  156. this.bestscoreText.text = "" + best;
  157. this.scoreText.text = "" + score;
  158. };
  159. function Qp_l() {
  160. this.initialize();
  161. this.gameover = new Qp_p(score, best);
  162. this.gameover.visible = !1;
  163. this.addChild(this.gameover);
  164. this.logopicture = new createjs.Bitmap(queue.getResult("logo"));
  165. this.logopicture.setAnchorPoint(0.5, 0.5);
  166. this.logopicture.x = 320;
  167. this.logopicture.y = 340;
  168. this.addChild(this.logopicture);
  169. this.start = new Qp_n("btnframe", "startbtnlabel", qp_i, 180, 720);
  170. this.start.on("click", function () {
  171. this.gameover.visible = !0;
  172. this.removeChild(this.logopicture);
  173. this.logopicture = null;
  174. }, this, !0);
  175. this.addChild(this.start);
  176. this.top = new Qp_n("btnframe", "topbtnlabel", qp_j, 460, 720);
  177. this.addChild(this.top);
  178. }
  179. Qp_l.prototype = new createjs.Container;
  180. function Qp_m() {
  181. this.initialize();
  182. this.ballLayer = new createjs.Container;
  183. this.addChild(this.ballLayer);
  184. var a = new createjs.Bitmap(queue.getResult("scorelabel"));
  185. a.setAnchorPoint(0, 0.5);
  186. a.x = 30;
  187. a.y = 50;
  188. this.addChild(a);
  189. this.scoreText = new createjs.Text("0", "bold 48px Arial", "#ff9d36");
  190. this.scoreText.stroke = "white";
  191. this.scoreText.textBaseline = "middle";
  192. this.scoreText.x = 140;
  193. this.scoreText.y = 50;
  194. this.addChild(this.scoreText);
  195. a = new createjs.Bitmap(queue.getResult("line"));
  196. a.setAnchorPoint(0.5, 0.5);
  197. a.x = 320;
  198. a.y = qp_d;
  199. this.addChild(a);
  200. }
  201. Qp_m.prototype = new createjs.Container;
  202. Qp_m.prototype.randomBalls = function () {
  203. var a = new Qp_q(queue, ["ballgreen", "ballred", "ballblue"][parseInt(3 * Math.random())], 506 * Math.random() + 67);
  204. qp_b.push(a);
  205. this.ballLayer.addChild(a);
  206. };
  207. Qp_m.prototype.doReset = function () {
  208. this.ballLayer.removeAllChildren();
  209. this.scoreText.text = "" + score;
  210. };
  211. function update(a) {
  212. 5 > qp_b.length && score / 5 + 1 > qp_b.length && qp_a.gameplayinglayer.randomBalls();
  213. a = a.delta / 1300;
  214. for (var c in qp_b) {
  215. if (qp_b[c].refreshLoop(a)) {
  216. return qp_a.gameover();
  217. }
  218. }
  219. }
  220. createjs.DisplayObject.prototype.setAnchorPoint = function (a, c) {
  221. var b = this.getBounds();
  222. this.regX = b.width * a;
  223. this.regY = b.height * c;
  224. };
  225. createjs.Container.prototype.addCenterChild = function (a) {
  226. a.setAnchorPoint(0.5, 0.5);
  227. var c = this.getBounds();
  228. a.x = c.x + 0.5 * c.width;
  229. a.y = c.y + 0.5 * c.height;
  230. this.addChild(a);
  231. };
  232. function Qp_q(a, c, b) {
  233. this.initialize();
  234. this.ball = new createjs.Bitmap(a.getResult(c));
  235. this.ball.setAnchorPoint(0.5, 0.5);
  236. this.addChild(this.ball);
  237. this.doReset(b);
  238. this.on("mousedown", function (a) {
  239. IS_TOUCH && a.nativeEvent instanceof MouseEvent || this.touch(a.localX, a.localY);
  240. }, this);
  241. }
  242. Qp_q.prototype = new createjs.Container;
  243. Qp_q.prototype.doReset = function (a) {
  244. this.y = -67;
  245. this.x = a;
  246. this.vx = this.vy = 0;
  247. this.ball.rotation = 0;
  248. };
  249. Qp_q.prototype.touch = function (a, c) {
  250. if (this.y > qp_d) {
  251. var b = this.x, d = Math.abs(Math.sqrt(2 * qp_c * this.y));
  252. if (320 <= b) {
  253. var e = (-d - Math.sqrt(4000 * qp_c)) / qp_c;
  254. this.vx = b / e;
  255. } else {
  256. e = (-d - Math.sqrt(4000 * qp_c)) / qp_c, this.vx = (b - 640) / e;
  257. }
  258. this.vy = -d;
  259. 0 > this.vy && (score++, qp_a.gameplayinglayer.scoreText.text = score);
  260. }
  261. };
  262. Qp_q.prototype.refreshLoop = function (a) {
  263. this.vy += qp_c * a;
  264. this.y += this.vy * a;
  265. this.x += this.vx * a;
  266. this.mouseEnabled = 0 < this.vy;
  267. this.ball.rotation = (this.ball.rotation + 100 * a) % 360;
  268. 0 >= this.x - 67 ? this.vx = Math.abs(this.vx) : this.x + 67 >= W && (this.vx = -Math.abs(this.vx));
  269. return this.y >= H;
  270. };