main.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. document.body.addEventListener('touchmove', bodyScroll, { passive: false });
  2. function bodyScroll(event) {
  3. event.preventDefault();
  4. }
  5. var canvas = document.getElementById("canvas");
  6. var stage = new createjs.Stage(canvas);
  7. window.user_info = {
  8. uid: 0,
  9. logo:'http://img5q.duitang.com/uploads/item/201502/25/20150225060808_wuANL.jpeg',//用户头像
  10. nickname:'用户昵称',//用户昵称,
  11. namemsg:'那个她/他',//寄语
  12. textmsg:'GOOD GOOD STUDY,DAY DAY UP'//寄语
  13. };
  14. var URLParams = new Array() , chooseType = 0 , dishType = 0;
  15. var params = document.location.search.substr(1).split('&');
  16. var ua = navigator.userAgent.toLowerCase() , url = "" , type = 0;
  17. for (i=0; i < params.length ; i++){
  18. var aParam = params[i].split('=');
  19. URLParams[aParam[0]] = aParam[1];
  20. }
  21. function init() {
  22. var comp = AdobeAn.getComposition("5529E26743974F469545223C44E61D22");
  23. var lib = comp.getLibrary();
  24. var loader = new createjs.LoadQueue(false);
  25. loader.addEventListener("fileload", function(evt) { handleFileLoad(evt, comp) });
  26. loader.addEventListener("complete", function(evt) { handleComplete(evt, comp) });
  27. loader.addEventListener("progress", loadProgressHandler);
  28. var lib = comp.getLibrary();
  29. loader.loadManifest(lib.properties.manifest);
  30. createjs.MotionGuidePlugin.install();
  31. createjs.Touch.enable(stage);
  32. }
  33. function handleFileLoad(evt, comp) {
  34. var loadingimages = comp.getImages();
  35. if (evt && (evt.item.type == "image")) {
  36. loadingimages[evt.item.id] = evt.result;
  37. }
  38. }
  39. function loadProgressHandler(event) {
  40. var num = Math.floor(event.progress * 100);
  41. $("#loadingTxt").text(num);
  42. $("#loadingBar").css("width", num + '%');
  43. }
  44. function handleComplete(evt, comp) {
  45. //This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
  46. var lib = comp.getLibrary();
  47. var ss = comp.getSpriteSheet();
  48. var queue = evt.target;
  49. var ssMetadata = lib.ssMetadata;
  50. for (i = 0; i < ssMetadata.length; i++) {
  51. ss[ssMetadata[i].name] = new createjs.SpriteSheet({ "images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames })
  52. }
  53. var exportRoot = new lib.assets();
  54. $(".loading").fadeOut(function(){
  55. $(".select-dish-box").find(".animated").removeClass("js-an");
  56. });
  57. var dishIndex = 0;
  58. $(".select-dish-box .item").on("click", function() {
  59. $(this).addClass("active").siblings().removeClass("active");
  60. $(".select-dish-box .confirm").show();
  61. })
  62. $(".select-dish-box .confirm").on("click", function() {
  63. if (!$(".select-dish-box .item").hasClass("active")) {
  64. alert("请选择你要做的菜")
  65. return false;
  66. }
  67. dishIndex = $(".select-dish-box .item.active").index();
  68. $(".select-dish-box").hide();
  69. $(".game-box").show();
  70. // 判断是哪个菜
  71. if(dishIndex == 0){
  72. exportRoot.plate.hsr_icon1.alpha = 1;
  73. exportRoot.plate.hsr_icon2.alpha = 1;
  74. exportRoot.plate.hsr_icon3.alpha = 1;
  75. exportRoot.plate.hsr_icon4.alpha = 1;
  76. cutDishArr = hsr_iconArr;
  77. $('#poster').attr('src','./img/poster/hsr.png');
  78. }else if(dishIndex == 1){
  79. exportRoot.plate.qcdf_icon1.alpha = 1;
  80. exportRoot.plate.qcdf_icon2.alpha = 1;
  81. exportRoot.plate.qcdf_icon3.alpha = 1;
  82. exportRoot.plate.qcdf_icon4.alpha = 1;
  83. exportRoot.plate.qcdf_icon5.alpha = 1;
  84. cutDishArr = qcdf_iconArr;
  85. $('#poster').attr('src','./img/poster/qcdf.png');
  86. }else if(dishIndex == 2){
  87. exportRoot.plate.swy_icon1.alpha = 1;
  88. exportRoot.plate.swy_icon2.alpha = 1;
  89. cutDishArr = swy_iconArr;
  90. $('#poster').attr('src','./img/poster/swy.png');
  91. }else{
  92. exportRoot.plate.ymc_icon1.alpha = 1;
  93. exportRoot.plate.ymc_icon2.alpha = 1;
  94. exportRoot.plate.ymc_icon3.alpha = 1;
  95. exportRoot.plate.ymc_icon4.alpha = 1;
  96. cutDishArr = ymc_iconArr;
  97. $('#poster').attr('src','./img/poster/ymc.png');
  98. }
  99. })
  100. $(".replay-btn").on("click",function(){
  101. URLParams = new Array();
  102. window.location.href = "http://wx.ttkuaiban.com/minigame/";
  103. //location.reload()
  104. })
  105. $(".secret-btn").on("click",function(){
  106. $(".secret-box").fadeIn();
  107. })
  108. $(".secret-box").on("click",function(){
  109. $(".secret-box").fadeOut();
  110. })
  111. function ballAnim(dom) {
  112. var anim = new TimelineMax({ repeat: -1 });
  113. anim.to(dom, 0.15, { rotation: "-=15", ease: Power0.easeIn })
  114. .to(dom, 0.3, { rotation: "+=30", ease: Power0.easeIn })
  115. .to(dom, 0.3, { rotation: "-=30", ease: Power0.easeIn })
  116. .to(dom, 0.3, { rotation: "+=30", ease: Power0.easeIn })
  117. .to(dom, 0.15, { rotation: "-=15", ease: Power0.easeIn });
  118. return anim;
  119. }
  120. function materialAnim(dom, x, y, callback) {
  121. var anim = new TimelineMax({ onComplete: callback });
  122. anim.to(dom, 0.5, { x: "+=" + x, y: "+=" + y, ease: Power0.easeIn })
  123. .to(dom, 0.3, { rotation: "-=25", ease: Power0.easeIn })
  124. .to(dom, 0.3, { rotation: "+=25", ease: Power0.easeIn })
  125. .to(dom, 0.3, { rotation: "-=25", ease: Power0.easeIn })
  126. .to(dom, 0.3, { rotation: "+=25", ease: Power0.easeIn });
  127. return anim;
  128. }
  129. function oilAnim(){
  130. if(dishIndex != 2){
  131. var dom = exportRoot.pot.oil;
  132. }else{
  133. var dom = exportRoot.bowl.oil;
  134. }
  135. var anim = new TimelineMax({ delay:0.8});
  136. anim.to(dom, 0.4, { alpha: 1, ease: Power0.easeIn })
  137. .to(dom, 1, { scale: 1, ease: Power0.easeIn })
  138. return anim;
  139. }
  140. function bowlAnim(callback) {
  141. var anim = new TimelineMax({ onComplete: callback, delay: 0.3 });
  142. anim.to(exportRoot.plate, 0.5, { y: "-=370", ease: Power0.easeIn })
  143. .to(exportRoot.bowl, 0.5, { alpha: 1, ease: Power0.easeIn });
  144. return anim;
  145. }
  146. function proAnim(callback) {
  147. var anim = new TimelineMax({ onComplete: callback, delay: 0.5 });
  148. anim.to(exportRoot.pro.proImg, 0.5, { rotation: "-=25", ease: Power0.easeIn })
  149. .to(exportRoot.pro.oil_icon1, 0.3, {alpha:1})
  150. .to(exportRoot.pro.oil_icon2, 0.2, {alpha:1})
  151. .to(exportRoot.pro.proImg, 1, {})
  152. .to(exportRoot.pro, 0.3, { alpha: 0, ease: Power0.easeIn })
  153. .to(exportRoot.pro, 1, {})
  154. return anim;
  155. }
  156. function oilIconAnim() {
  157. oilAnim();
  158. var anim = new TimelineMax({ repeat:10,delay:1});
  159. anim.to(exportRoot.pro.oil_icon2, 0.3, {y:"+=100",alpha:0})
  160. return anim;
  161. }
  162. function btnAnim(dom){
  163. var anim = new TimelineMax({ repeat:-1 });
  164. anim.to(dom, 0.3, { scale: "+=0.1", ease: Power0.easeIn })
  165. .to(dom, 0.3, { scale: "-=0.1", ease: Power0.easeIn })
  166. return anim;
  167. }
  168. function fadeInAnim(dom){
  169. var anim = new TimelineMax({ });
  170. anim.to(dom, 0.4, { alpha: 1, ease: Power0.easeIn })
  171. return anim;
  172. }
  173. function materialEnterAnim(dom,delay){
  174. dom.scale = 0.1;
  175. delay = delay || 0.1;
  176. var anim = new TimelineMax({ delay:delay});
  177. anim.to(dom,1.2, { scale: 1, ease: Elastic.easeOut.config(1, 0.3) })
  178. return anim;
  179. }
  180. var cutDishArr = [];
  181. // 油麦菜
  182. var ymc_iconArr = [
  183. {
  184. x: exportRoot.plate.x + exportRoot.plate.ymc_icon1.x,
  185. y: exportRoot.plate.y + exportRoot.plate.ymc_icon1.y,
  186. width: 266,
  187. height: 187,
  188. isClear: false
  189. },
  190. {
  191. x: exportRoot.plate.x + exportRoot.plate.ymc_icon2.x,
  192. y: exportRoot.plate.y + exportRoot.plate.ymc_icon2.y,
  193. width: 103,
  194. height: 118,
  195. isClear: false
  196. },
  197. {
  198. x: exportRoot.plate.x + exportRoot.plate.ymc_icon3.x,
  199. y: exportRoot.plate.y + exportRoot.plate.ymc_icon3.y,
  200. width: 371,
  201. height: 144,
  202. isClear: false
  203. },
  204. {
  205. x: exportRoot.plate.x + exportRoot.plate.ymc_icon4.x,
  206. y: exportRoot.plate.y + exportRoot.plate.ymc_icon4.y,
  207. width: 86,
  208. height: 75,
  209. isClear: false
  210. }
  211. ]
  212. // 三文鱼
  213. var swy_iconArr = [
  214. {
  215. x: exportRoot.plate.x + exportRoot.plate.hsr_icon1.x,
  216. y: exportRoot.plate.y + exportRoot.plate.hsr_icon1.y,
  217. width: 262,
  218. height: 195,
  219. isClear: false
  220. }
  221. ]
  222. // 红烧肉的位置
  223. var hsr_iconArr = [{
  224. x: exportRoot.plate.x + exportRoot.plate.hsr_icon1.x,
  225. y: exportRoot.plate.y + exportRoot.plate.hsr_icon1.y,
  226. width: 202,
  227. height: 129,
  228. isClear: false
  229. },
  230. {
  231. x: exportRoot.plate.x + exportRoot.plate.hsr_icon2.x,
  232. y: exportRoot.plate.y + exportRoot.plate.hsr_icon2.y,
  233. width: 86,
  234. height: 75,
  235. isClear: false
  236. },
  237. {
  238. x: exportRoot.plate.x + exportRoot.plate.hsr_icon3.x,
  239. y: exportRoot.plate.y + exportRoot.plate.hsr_icon3.y,
  240. width: 371,
  241. height: 144,
  242. isClear: false
  243. },
  244. {
  245. x: exportRoot.plate.x + exportRoot.plate.hsr_icon4.x,
  246. y: exportRoot.plate.y + exportRoot.plate.hsr_icon4.y,
  247. width: 103,
  248. height: 118,
  249. isClear: false
  250. }
  251. ];
  252. // 青菜豆腐的位置
  253. var qcdf_iconArr = [{
  254. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon1.x,
  255. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon1.y,
  256. width: 169,
  257. height: 320,
  258. isClear: false
  259. },
  260. {
  261. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon2.x,
  262. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon2.y,
  263. width: 207,
  264. height: 144,
  265. isClear: false
  266. },
  267. {
  268. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon3.x,
  269. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon3.y,
  270. width: 103,
  271. height: 118,
  272. isClear: false
  273. },
  274. {
  275. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon4.x,
  276. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon4.y,
  277. width: 371,
  278. height: 144,
  279. isClear: false
  280. },
  281. {
  282. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon5.x,
  283. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon5.y,
  284. width: 86,
  285. height: 75,
  286. isClear: false
  287. }
  288. ]
  289. // 画线
  290. var lineArr = [];
  291. var lineTimr = null;
  292. var lineShape = new createjs.Shape();
  293. function drawLine() {
  294. var value = 40;
  295. lineTimr = setInterval(function() {
  296. lineShape.graphics.clear();
  297. lineShape.graphics.setStrokeStyle(8).beginStroke("#787878");
  298. if (lineArr.length) {
  299. lineShape.graphics.moveTo(lineArr[0].x, lineArr[0].y);
  300. }
  301. for (var i = 0; i < lineArr.length; i++) {
  302. var x = lineArr[i].x;
  303. var y = lineArr[i].y;
  304. lineShape.graphics.lineTo(x, y);
  305. for (var p = 0; p < cutDishArr.length; p++) {
  306. if (x-cutDishArr[p].width/3 > cutDishArr[p].x && x < (cutDishArr[p].x + cutDishArr[p].width)) {
  307. if (y-cutDishArr[p].height/3 > cutDishArr[p].y && y < (cutDishArr[p].y + cutDishArr[p].height)) {
  308. if (cutDishArr[p].isClear == false) {
  309. cutDishArr[p].isClear = true;
  310. if(dishIndex == 0){
  311. exportRoot.plate['hsr_icon' + (p + 1)].gotoAndStop(1);
  312. }else if(dishIndex == 1){
  313. exportRoot.plate['qcdf_icon' + (p + 1)].gotoAndStop(1);
  314. }else if(dishIndex == 2){
  315. exportRoot.plate.swy_icon1.gotoAndStop(1);
  316. }else{
  317. exportRoot.plate['ymc_icon' + (p + 1)].gotoAndStop(1);
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. lineArr.splice(0, 1);
  325. }, 30)
  326. }
  327. // 画线事件
  328. drawLine();
  329. exportRoot.addEventListener("mousedown", function(event) {
  330. lineArr = [];
  331. var obj = {
  332. x: event.stageX,
  333. y: event.stageY,
  334. };
  335. lineArr.push(obj);
  336. })
  337. exportRoot.addEventListener("pressmove", function(event) {
  338. if (lineArr.length >= 15) {
  339. lineArr.splice(0, 1);
  340. }
  341. var obj = {
  342. x: event.stageX,
  343. y: event.stageY,
  344. };
  345. lineArr.push(obj);
  346. })
  347. exportRoot.addEventListener("pressup", function(event) {
  348. playbowlAnim();
  349. })
  350. var dishMoveIndex = 0;
  351. // 移动菜品
  352. function dishMove(dom,x,y) {
  353. var startX = 0;
  354. var startY = 0;
  355. var domFirst = $.extend(true, {}, dom);
  356. dom.addEventListener("mousedown", function(event) {
  357. startX = event.stageX;
  358. startY = event.stageY;
  359. })
  360. dom.addEventListener("pressmove", function(event) {
  361. dom.x -= (startX - event.stageX);
  362. dom.y -= (startY - event.stageY);
  363. startX = event.stageX;
  364. startY = event.stageY;
  365. })
  366. dom.addEventListener("pressup", function(event) {
  367. if (dom.x + exportRoot.plate.x > 80 && dom.y + exportRoot.plate.y > 518) {
  368. dom.x = 190 - exportRoot.plate.x + x;
  369. dom.y = 630 - exportRoot.plate.y + y;
  370. dom.removeAllEventListeners();
  371. if(dishIndex == 0){
  372. ++dishMoveIndex;
  373. if (dishMoveIndex >= 4) {
  374. exportRoot.btn1.alpha = 1;
  375. btnAnim(exportRoot.btn1);
  376. isAllInplate();
  377. }
  378. }else if(dishIndex == 1){
  379. ++dishMoveIndex;
  380. if (dishMoveIndex >= 5) {
  381. exportRoot.btn1.alpha = 1;
  382. btnAnim(exportRoot.btn1);
  383. isAllInplate();
  384. }
  385. }else if(dishIndex == 2){
  386. exportRoot.btn1.alpha = 1;
  387. btnAnim(exportRoot.btn1);
  388. isAllInplate();
  389. }else{
  390. ++dishMoveIndex;
  391. if (dishMoveIndex >= 4) {
  392. exportRoot.btn1.alpha = 1;
  393. btnAnim(exportRoot.btn1);
  394. isAllInplate();
  395. }
  396. }
  397. } else {
  398. dom.x = domFirst.x;
  399. dom.y = domFirst.y;
  400. }
  401. })
  402. }
  403. // 菜全部到盘子里
  404. function isAllInplate() {
  405. exportRoot.btn1.addEventListener("mousedown", function() {
  406. exportRoot.btn1.removeAllEventListeners();
  407. exportRoot.btn1.alpha = 0;
  408. exportRoot.pro.alpha = 1;
  409. if(dishIndex != 2){
  410. exportRoot.bowl.alpha = 0;
  411. exportRoot.plate.alpha = 0;
  412. exportRoot.pot.alpha = 1;
  413. }else{
  414. exportRoot.plate.instance.alpha = 0;
  415. exportRoot.plate.swy_icon2.alpha = 0;
  416. }
  417. oilIconAnim();
  418. proAnim(function() {
  419. exportRoot.btn2.alpha = 1;
  420. btnAnim(exportRoot.btn2);
  421. if(dishIndex == 0){
  422. fadeInAnim(exportRoot.pot.hsr);
  423. }else if(dishIndex == 1){
  424. fadeInAnim(exportRoot.pot.qcdf);
  425. }else if(dishIndex == 3){
  426. fadeInAnim(exportRoot.pot.ymc);
  427. }
  428. });
  429. })
  430. exportRoot.btn2.addEventListener("mousedown", function() {
  431. exportRoot.btn2.removeAllEventListeners();
  432. exportRoot.btn2.alpha = 0;
  433. fadeInAnim(exportRoot.blackboard);
  434. materialEnterAnim(exportRoot.blackboard.material1,0.2);
  435. materialEnterAnim(exportRoot.blackboard.material2,0.4);
  436. materialEnterAnim(exportRoot.blackboard.material3,0.6);
  437. exportRoot.ball1.alpha = 1;
  438. ballAnim(exportRoot.ball1);
  439. })
  440. exportRoot.blackboard.material1.addEventListener("mousedown", function() {
  441. exportRoot.blackboard.material1.removeAllEventListeners();
  442. exportRoot.blackboard.material2.removeAllEventListeners();
  443. exportRoot.blackboard.material3.removeAllEventListeners();
  444. chooseType = 3;
  445. $(".poster-mode").addClass("poster-bg3");
  446. materialAnim(exportRoot.blackboard.material1, 300, 180, function() {
  447. exportRoot.blackboard.material1.x -=300;
  448. exportRoot.blackboard.material1.y -=180;
  449. $(".shake-mode").show();
  450. shakeInit();
  451. });
  452. })
  453. exportRoot.blackboard.material2.addEventListener("mousedown", function() {
  454. exportRoot.blackboard.material1.removeAllEventListeners();
  455. exportRoot.blackboard.material2.removeAllEventListeners();
  456. exportRoot.blackboard.material3.removeAllEventListeners();
  457. chooseType = 2;
  458. $(".poster-mode").addClass("poster-bg2");
  459. materialAnim(exportRoot.blackboard.material2, 120, 180, function() {
  460. exportRoot.blackboard.material2.x -=120;
  461. exportRoot.blackboard.material2.y -=180;
  462. $(".shake-mode").show();
  463. shakeInit();
  464. });
  465. })
  466. exportRoot.blackboard.material3.addEventListener("mousedown", function() {
  467. exportRoot.blackboard.material1.removeAllEventListeners();
  468. exportRoot.blackboard.material2.removeAllEventListeners();
  469. exportRoot.blackboard.material3.removeAllEventListeners();
  470. chooseType = 1;
  471. $(".poster-mode").addClass("poster-bg1");
  472. materialAnim(exportRoot.blackboard.material3, -30, 180, function() {
  473. exportRoot.blackboard.material3.x +=30;
  474. exportRoot.blackboard.material3.y -=180;
  475. $(".shake-mode").show();
  476. shakeInit();
  477. });
  478. })
  479. }
  480. // 菜切完盘子上移动
  481. function playbowlAnim() {
  482. for (var i = 0; i < cutDishArr.length; i++) {
  483. if (cutDishArr[i].isClear == false) {
  484. return false;
  485. }
  486. }
  487. stage.removeChild(lineShape);
  488. clearInterval(lineTimr);
  489. exportRoot.removeAllEventListeners();
  490. bowlAnim(function() {
  491. if(dishIndex == 0){
  492. dishMove(exportRoot.plate.hsr_icon1,0,0);
  493. dishMove(exportRoot.plate.hsr_icon2,0,0);
  494. dishMove(exportRoot.plate.hsr_icon3,0,0);
  495. dishMove(exportRoot.plate.hsr_icon4,0,0);
  496. }else if(dishIndex == 1){
  497. dishMove(exportRoot.plate.qcdf_icon1,0,-80);
  498. dishMove(exportRoot.plate.qcdf_icon2,0,0);
  499. dishMove(exportRoot.plate.qcdf_icon3,0,0);
  500. dishMove(exportRoot.plate.qcdf_icon4,0,0);
  501. dishMove(exportRoot.plate.qcdf_icon5,0,0);
  502. }else if(dishIndex == 2){
  503. dishMove(exportRoot.plate.swy_icon1,120,100);
  504. }else{
  505. dishMove(exportRoot.plate.ymc_icon1,0,0);
  506. dishMove(exportRoot.plate.ymc_icon2,0,0);
  507. dishMove(exportRoot.plate.ymc_icon3,0,0);
  508. dishMove(exportRoot.plate.ymc_icon4,0,0);
  509. }
  510. });
  511. }
  512. function shakeInit() {
  513. if (window.DeviceMotionEvent) {
  514. window.addEventListener('devicemotion', deviceMotionHandler, false);
  515. } else {
  516. alert('您的手机不支持摇一摇功能!');
  517. }
  518. setTimeout(function(){
  519. window.removeEventListener('devicemotion', deviceMotionHandler, false);
  520. exportRoot.pot.hsr.play();
  521. exportRoot.btn3.alpha = 1;
  522. btnAnim(exportRoot.btn3);
  523. exportRoot.btn3.addEventListener("mousedown",function(){
  524. exportRoot.btn3.removeAllEventListeners();
  525. var href = document.location.href + "&type=" + chooseType + "&food=" + dishIndex;
  526. history.pushState("", "Title", href);
  527. $(".poster-mode").fadeIn();
  528. })
  529. if(dishIndex == 0){
  530. exportRoot.pot.hsr.gotoAndStop(1);
  531. }else if(dishIndex == 1){
  532. exportRoot.pot.qcdf.gotoAndStop(1);
  533. }else if(dishIndex == 2){
  534. exportRoot.bowl.oil.alpha = 0;
  535. exportRoot.plate['swy_icon1'].gotoAndStop(2);
  536. }else{
  537. exportRoot.pot.ymc.gotoAndStop(1);
  538. }
  539. $(".shake-mode").fadeOut();
  540. },3000)
  541. //获取加速度信息
  542. //通过监听上一步获取到的x, y, z 值在一定时间范围内的变化率,进行设备是否有进行晃动的判断。
  543. //而为了防止正常移动的误判,需要给该变化率设置一个合适的临界值。
  544. var SHAKE_THRESHOLD = 8000; //阈值越大,触发摇晃事件时手机摇晃的程度越剧烈
  545. var last_update = 0;
  546. var x, y, z, last_x = 0,
  547. last_y = 0,
  548. last_z = 0;
  549. function deviceMotionHandler(eventData) {
  550. var acceleration = eventData.accelerationIncludingGravity;
  551. var curTime = new Date().getTime();
  552. if ((curTime - last_update) > 10) {
  553. var diffTime = curTime - last_update;
  554. last_update = curTime;
  555. x = acceleration.x;
  556. y = acceleration.y;
  557. z = acceleration.z;
  558. var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
  559. if (speed > SHAKE_THRESHOLD) {
  560. //dosomething
  561. $("#fire").addClass("anim-time");
  562. }else{
  563. $("#fire").removeClass("anim-time");
  564. }
  565. last_x = x;
  566. last_y = y;
  567. last_z = z;
  568. }
  569. }
  570. }
  571. //Registers the "tick" event listener.
  572. function fnStartAnimation() {
  573. stage.addChild(exportRoot, lineShape);
  574. createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED;
  575. createjs.Ticker.addEventListener("tick", stage);
  576. }
  577. fnStartAnimation();
  578. stageBreakHandler();
  579. }
  580. function getInfo() {
  581. var ua = navigator.userAgent.toLowerCase();
  582. if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  583. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  584. type = 0;
  585. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  586. +"appid=wx749c84daac654e1e&"
  587. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  588. +"response_type=code&"
  589. +"scope=snsapi_userinfo&"//snsapi_userinfo
  590. +"state=1#wechat_redirect";
  591. getMsg();
  592. }
  593. if (ua.match(/WeiBo/i) == "weibo") {
  594. type = 1;
  595. url = "https://api.weibo.com/oauth2/authorize?"
  596. +"client_id=2141531565&"
  597. +"response_type=code&"
  598. +"redirect_uri=http://wx.ttkuaiban.com/minigame/index.html"
  599. getMsg();
  600. }
  601. } else {
  602. var ua = navigator.userAgent.toLowerCase();
  603. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  604. type = 0;
  605. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  606. +"appid=wx749c84daac654e1e&"
  607. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  608. +"response_type=code&"
  609. +"scope=snsapi_userinfo&"//snsapi_userinfo
  610. +"state=1#wechat_redirect";
  611. getMsg();
  612. }
  613. }
  614. if(URLParams['uid']) {
  615. $('#nameInput').hide();
  616. $('#nameText').show();
  617. $('#textInput').hide();
  618. $('#text').show();
  619. chooseType = URLParams['type'];
  620. dishType = URLParams['food'];
  621. $(".poster-mode").addClass("poster-bg" + chooseType);
  622. if(dishIndex == 0){
  623. $('#poster').attr('src','./img/poster/hsr.png');
  624. }else if(dishIndex == 1){
  625. $('#poster').attr('src','./img/poster/qcdf.png');
  626. }else if(dishIndex == 2){
  627. $('#poster').attr('src','./img/poster/swy.png');
  628. }else{
  629. $('#poster').attr('src','./img/poster/ymc.png');
  630. }
  631. $(".poster-mode").fadeIn();
  632. } else {
  633. $('#nameInput').show();
  634. $('#nameText').hide();
  635. $('#textInput').show();
  636. $('#text').hide();
  637. init();
  638. }
  639. }
  640. // 获取登陆信息
  641. function getMsg(){
  642. if(URLParams['uid']){
  643. var uid = URLParams['uid'];
  644. var xhr=null;
  645. try{
  646. xhr=new XMLHttpRequest();
  647. }catch(e){
  648. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  649. }
  650. xhr.open("post","news/show",true);
  651. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  652. xhr.send("id="+uid);
  653. xhr.onreadystatechange=function(){
  654. if(xhr.readyState==4){
  655. if(xhr.status==200){
  656. var msg = JSON.parse(xhr.response);
  657. if(msg.code == "ok") {
  658. window.user_info.uid = msg.data.id;
  659. window.user_info.logo = msg.data.headerPic;
  660. window.user_info.nickname = msg.data.nickName;
  661. window.user_info.namemsg = msg.data.message;
  662. window.user_info.textmsg = msg.data.message;
  663. $('.headimg-box img').attr("src", msg.data.headerPic);
  664. $('.user-info p').html(msg.data.nickName);
  665. $('#nameText').html(msg.data.receiver);
  666. $('#text').html(msg.data.message);
  667. }
  668. }else{
  669. console.log("错误"+xhr.status)
  670. }
  671. }
  672. }
  673. }else {
  674. if(URLParams['code']){
  675. var code = URLParams['code'];
  676. var xhr=null;
  677. try{
  678. xhr=new XMLHttpRequest();
  679. }catch(e){
  680. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  681. }
  682. xhr.open("post","user/weiXinLogin",true);
  683. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  684. xhr.send("code="+code+"&type="+type);
  685. xhr.onreadystatechange=function(){
  686. if(xhr.readyState==4){
  687. if(xhr.status==200){
  688. var msg = JSON.parse(xhr.response);
  689. if(msg.code == "ok") {
  690. window.user_info.uid = msg.data.id;
  691. window.user_info.logo = msg.data.headerPic;
  692. window.user_info.nickname = msg.data.nickName;
  693. $('.headimg-box img').attr("src", msg.data.headerPic);
  694. $('.user-info p').html(msg.data.nickName);
  695. }
  696. }else{
  697. console.log("错误"+xhr.status)
  698. }
  699. }
  700. }
  701. } else {
  702. window.location.href = url;
  703. }
  704. }
  705. }
  706. function saveText() {
  707. var value = $('#textInput').val(),
  708. receiver = $('#nameInput').val();
  709. var xhr=null;
  710. try{
  711. xhr=new XMLHttpRequest();
  712. }catch(e){
  713. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  714. }
  715. xhr.open("post","news/addNews",true);
  716. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  717. xhr.send("receiver="+receiver+"&message="+value+"&userId="+window.user_info.uid);
  718. xhr.onreadystatechange=function(){
  719. if(xhr.readyState==4){
  720. if(xhr.status==200){
  721. var msg = JSON.parse(xhr.response) , href = document.location.href;
  722. if(msg.code == "ok") {
  723. window.user_info.uid = msg.data.id;
  724. window.user_info.logo = msg.data.headerPic;
  725. window.user_info.nickname = msg.data.nickName;
  726. window.user_info.namemsg = msg.data.receiver;
  727. window.user_info.textmsg = msg.data.message;
  728. $('.headimg-box img').attr("src", msg.data.headerPic);
  729. $('.user-info p').html(msg.data.nickName);
  730. $('#nameInput').val(msg.data.receiver);
  731. $('#textInput').val(msg.data.message);
  732. href = document.location.href + "&uid=" + msg.data.id;
  733. }
  734. if(href != document.location.href){
  735. history.pushState("", "Title", href);
  736. }
  737. if(type == 1) {
  738. setTimeout(function(){
  739. window.location.href = url
  740. }, 6000);
  741. }
  742. }else{
  743. console.log("错误"+xhr.status)
  744. }
  745. }
  746. }
  747. }
  748. $(".replay-btn").on("click",function(){
  749. URLParams = new Array();
  750. window.location.href = "http://wx.ttkuaiban.com/minigame/";
  751. //location.reload()
  752. })
  753. $(".secret-btn").on("click",function(){
  754. $(".secret-box").fadeIn();
  755. })
  756. $(".secret-box").on("click",function(){
  757. $(".secret-box").fadeOut();
  758. })
  759. // 自适应
  760. var stageWidth, stageHeight, stageScale;
  761. function stageBreakHandler(event) {
  762. if (stageWidth != $(".warp").width() || stageHeight != $(".warp").height()) {
  763. stageWidth = $(".warp").width();
  764. stageHeight = $(".warp").height();
  765. stageScale = stageWidth / 640;
  766. canvas.style.width = 640 * stageScale + 'px';
  767. canvas.style.height = 1040 * stageScale + 'px';
  768. }
  769. }