main.js 42 KB

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