main.js 31 KB

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