main.js 33 KB

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