main.js 31 KB

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