main.js 40 KB

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