main.js 32 KB

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