main.js 33 KB

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