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. 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. }else{
  457. exportRoot.btn2.alpha = 1;
  458. }
  459. });
  460. })
  461. exportRoot.btn2.addEventListener("mousedown", function() {
  462. exportRoot.btn2.removeAllEventListeners();
  463. exportRoot.btn2.alpha = 0;
  464. fadeInAnim(exportRoot.blackboard);
  465. materialEnterAnim(exportRoot.blackboard.material1,0.2);
  466. materialEnterAnim(exportRoot.blackboard.material2,0.4);
  467. materialEnterAnim(exportRoot.blackboard.material3,0.6);
  468. exportRoot.ball1.alpha = 1;
  469. ballAnim(exportRoot.ball1);
  470. })
  471. exportRoot.blackboard.material1.addEventListener("mousedown", function() {
  472. exportRoot.blackboard.material1.removeAllEventListeners();
  473. exportRoot.blackboard.material2.removeAllEventListeners();
  474. exportRoot.blackboard.material3.removeAllEventListeners();
  475. $(".poster-mode").addClass("poster-bg3");
  476. materialAnim(exportRoot.blackboard.material1, 300, 180, function() {
  477. exportRoot.blackboard.material1.x -=300;
  478. exportRoot.blackboard.material1.y -=180;
  479. // $(".shake-mode").show();
  480. shakeInit();
  481. });
  482. })
  483. exportRoot.blackboard.material2.addEventListener("mousedown", function() {
  484. exportRoot.blackboard.material1.removeAllEventListeners();
  485. exportRoot.blackboard.material2.removeAllEventListeners();
  486. exportRoot.blackboard.material3.removeAllEventListeners();
  487. $(".poster-mode").addClass("poster-bg2");
  488. materialAnim(exportRoot.blackboard.material2, 120, 180, function() {
  489. exportRoot.blackboard.material2.x -=120;
  490. exportRoot.blackboard.material2.y -=180;
  491. // $(".shake-mode").show();
  492. shakeInit();
  493. });
  494. })
  495. exportRoot.blackboard.material3.addEventListener("mousedown", function() {
  496. exportRoot.blackboard.material1.removeAllEventListeners();
  497. exportRoot.blackboard.material2.removeAllEventListeners();
  498. exportRoot.blackboard.material3.removeAllEventListeners();
  499. $(".poster-mode").addClass("poster-bg1");
  500. materialAnim(exportRoot.blackboard.material3, -30, 180, function() {
  501. exportRoot.blackboard.material3.x +=30;
  502. exportRoot.blackboard.material3.y -=180;
  503. // $(".shake-mode").show();
  504. shakeInit();
  505. });
  506. })
  507. }
  508. // 菜切完盘子上移动
  509. function playbowlAnim() {
  510. for (var i = 0; i < cutDishArr.length; i++) {
  511. if (cutDishArr[i].isClear == false) {
  512. return false;
  513. }
  514. }
  515. stage.removeChild(lineShape);
  516. clearInterval(lineTimr);
  517. exportRoot.removeAllEventListeners();
  518. bowlAnim(function() {
  519. if(dishIndex == 0){
  520. dishMove(exportRoot.plate.hsr_icon1,0,0);
  521. dishMove(exportRoot.plate.hsr_icon2,0,0);
  522. dishMove(exportRoot.plate.hsr_icon3,0,0);
  523. dishMove(exportRoot.plate.hsr_icon4,0,0);
  524. }else if(dishIndex == 1){
  525. dishMove(exportRoot.plate.qcdf_icon1,0,-80);
  526. dishMove(exportRoot.plate.qcdf_icon2,0,0);
  527. dishMove(exportRoot.plate.qcdf_icon3,0,0);
  528. dishMove(exportRoot.plate.qcdf_icon4,0,0);
  529. dishMove(exportRoot.plate.qcdf_icon5,0,0);
  530. }else if(dishIndex == 2){
  531. dishMove(exportRoot.plate.swy_icon1,120,100);
  532. }else{
  533. dishMove(exportRoot.plate.ymc_icon1,0,0);
  534. dishMove(exportRoot.plate.ymc_icon2,0,0);
  535. dishMove(exportRoot.plate.ymc_icon3,0,0);
  536. dishMove(exportRoot.plate.ymc_icon4,0,0);
  537. }
  538. });
  539. }
  540. function shakeInit() {
  541. var shake_cnt = 0;
  542. $(".shake-mode2").show();
  543. if (window.DeviceMotionEvent) {
  544. window.addEventListener('devicemotion', deviceMotionHandler, false);
  545. } else {
  546. alert('您的手机不支持摇一摇功能!');
  547. }
  548. //获取加速度信息
  549. //通过监听上一步获取到的x, y, z 值在一定时间范围内的变化率,进行设备是否有进行晃动的判断。
  550. //而为了防止正常移动的误判,需要给该变化率设置一个合适的临界值。
  551. var SHAKE_THRESHOLD = 10000; //阈值越大,触发摇晃事件时手机摇晃的程度越剧烈
  552. var last_update = 0;
  553. var x, y, z, last_x = 0,
  554. last_y = 0,
  555. last_z = 0;
  556. function deviceMotionHandler(eventData) {
  557. var acceleration = eventData.accelerationIncludingGravity;
  558. var curTime = new Date().getTime();
  559. if ((curTime - last_update) > 10) {
  560. var diffTime = curTime - last_update;
  561. last_update = curTime;
  562. x = acceleration.x;
  563. y = acceleration.y;
  564. z = acceleration.z;
  565. var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
  566. if (speed > SHAKE_THRESHOLD) {
  567. $(".shake-mode2").hide();
  568. $(".shake-mode").show();
  569. shake_cnt++;
  570. if(shake_cnt>2){
  571. setTimeout(function(){
  572. window.removeEventListener('devicemotion', deviceMotionHandler, false);
  573. exportRoot.pot.hsr.play();
  574. // exportRoot.btn3.alpha = 1;
  575. // btnAnim(exportRoot.btn3);
  576. // exportRoot.btn3.addEventListener("mousedown",function(){
  577. // exportRoot.btn3.removeAllEventListeners();
  578. // $(".poster-mode").fadeIn();
  579. // })
  580. if(document.location.href.indexOf('type') == -1){
  581. var href = document.location.href + (document.location.href.indexOf('?') > -1?'&':'?') + "type=" + chooseType + "&food=" + dishIndex;
  582. history.pushState("", "Title", href);
  583. }
  584. if(dishIndex == 0){
  585. exportRoot.pot.hsr.gotoAndStop(1);
  586. }else if(dishIndex == 1){
  587. exportRoot.pot.qcdf.gotoAndStop(1);
  588. }else if(dishIndex == 2){
  589. exportRoot.bowl.oil.alpha = 0;
  590. exportRoot.plate['swy_icon1'].gotoAndStop(2);
  591. }else{
  592. exportRoot.pot.ymc.gotoAndStop(1);
  593. }
  594. $(".shake-mode").fadeOut();
  595. // exportRoot.btn3.removeAllEventListeners();
  596. $(".poster-mode").fadeIn();
  597. },3000)
  598. }
  599. //dosomething
  600. $("#fire").addClass("anim-time");
  601. }else{
  602. $("#fire").removeClass("anim-time");
  603. }
  604. last_x = x;
  605. last_y = y;
  606. last_z = z;
  607. // 开始火的动画
  608. $("#fire").removeClass("js-an");
  609. // $(".shake-dialog .icon").hide();
  610. // $(".shake-dialog .txt").hide();
  611. }
  612. }
  613. }
  614. //Registers the "tick" event listener.
  615. function fnStartAnimation() {
  616. stage.addChild(exportRoot, lineShape);
  617. createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED;
  618. createjs.Ticker.addEventListener("tick", stage);
  619. }
  620. fnStartAnimation();
  621. stageBreakHandler();
  622. }
  623. function getInfo() {
  624. var ua = navigator.userAgent.toLowerCase();
  625. var isMobile = false;
  626. if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  627. isMobile = true;
  628. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  629. type = 0;
  630. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  631. +"appid=wx749c84daac654e1e&"
  632. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  633. +"response_type=code&"
  634. +"scope=snsapi_userinfo&"//snsapi_userinfo
  635. +"state=1#wechat_redirect";
  636. }
  637. if (ua.match(/WeiBo/i) == "weibo") {
  638. type = 1;
  639. url = "https://api.weibo.com/oauth2/authorize?"
  640. +"client_id=2141531565&"
  641. +"response_type=code&"
  642. +"redirect_uri=http://wx.ttkuaiban.com/minigame/index.html"
  643. }
  644. } else {
  645. var ua = navigator.userAgent.toLowerCase();
  646. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  647. type = 0;
  648. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  649. +"appid=wx749c84daac654e1e&"
  650. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  651. +"response_type=code&"
  652. +"scope=snsapi_userinfo&"//snsapi_userinfo
  653. +"state=1#wechat_redirect";
  654. }
  655. }
  656. if(URLParams['uid']) {
  657. $('#nameInput').hide();
  658. $('#nameText').show();
  659. $('#textInput').hide();
  660. $('#text').show();
  661. $('.replay-btn').hide();
  662. $('.secret-btn').hide();
  663. chooseType = URLParams['type'];
  664. dishType = URLParams['food'];
  665. $(".poster-mode").addClass("poster-bg" + chooseType);
  666. if(dishType == 0){
  667. $('#poster').attr('src','./img/poster/hsr.png');
  668. }else if(dishType == 1){
  669. $('#poster').attr('src','./img/poster/qcdf.png');
  670. }else if(dishType == 2){
  671. $('#poster').attr('src','./img/poster/swy.png');
  672. }else{
  673. $('#poster').attr('src','./img/poster/ymc.png');
  674. }
  675. getMsg();
  676. $(".poster-mode").fadeIn();
  677. } else {
  678. $('#nameInput').show();
  679. $('#nameText').hide();
  680. $('#textInput').show();
  681. $('#text').hide();
  682. $('.replay-btn').show();
  683. $('.secret-btn').show();
  684. init();
  685. if (isMobile) {
  686. getMsg();
  687. }
  688. }
  689. }
  690. // 获取登陆信息
  691. function getMsg(){
  692. if(URLParams['uid'] || localStorage.userId){
  693. if(URLParams['uid']) {
  694. var uid = URLParams['uid'];
  695. var xhr=null;
  696. try{
  697. xhr=new XMLHttpRequest();
  698. }catch(e){
  699. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  700. }
  701. xhr.open("post","news/show",true);
  702. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  703. xhr.send("id="+uid);
  704. xhr.onreadystatechange=function(){
  705. if(xhr.readyState==4){
  706. if(xhr.status==200){
  707. var msg = JSON.parse(xhr.response);
  708. if(msg.code == "ok") {
  709. window.user_info.uid = msg.data.id;
  710. window.user_info.logo = msg.data.headerPic;
  711. window.user_info.nickname = msg.data.nickName;
  712. window.user_info.namemsg = msg.data.message;
  713. window.user_info.textmsg = msg.data.message;
  714. $('.headimg-box img').attr("src", msg.data.headerPic);
  715. $('.user-info p').html(msg.data.nickName);
  716. $('#nameText').html(msg.data.receiver);
  717. $('#text').html(msg.data.message);
  718. }
  719. }else{
  720. console.log("错误"+xhr.status)
  721. }
  722. }
  723. }
  724. } else {
  725. window.user_info.uid = localStorage.userId;
  726. window.user_info.logo = localStorage.userPic;
  727. window.user_info.nickname = localStorage.userName;
  728. $('.headimg-box img').attr("src", localStorage.userPic);
  729. $('.user-info p').html(localStorage.userName);
  730. }
  731. }else {
  732. if(URLParams['code']){
  733. var code = URLParams['code'];
  734. var xhr=null;
  735. try{
  736. xhr=new XMLHttpRequest();
  737. }catch(e){
  738. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  739. }
  740. xhr.open("post","user/weiXinLogin",true);
  741. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  742. xhr.send("code="+code+"&type="+type);
  743. xhr.onreadystatechange=function(){
  744. if(xhr.readyState==4){
  745. if(xhr.status==200){
  746. var msg = JSON.parse(xhr.response);
  747. if(msg.code == "ok") {
  748. window.user_info.uid = msg.data.id;
  749. localStorage.userId = msg.data.id;
  750. localStorage.userPic = msg.data.headerPic;
  751. localStorage.userName = msg.data.nickName;
  752. window.user_info.logo = msg.data.headerPic;
  753. window.user_info.nickname = msg.data.nickName;
  754. $('.headimg-box img').attr("src", msg.data.headerPic);
  755. $('.user-info p').html(msg.data.nickName);
  756. }
  757. }else{
  758. console.log("错误"+xhr.status)
  759. }
  760. }
  761. }
  762. } else {
  763. window.location.href = url;
  764. }
  765. }
  766. }
  767. function saveText() {
  768. var value = $('#textInput').val(),
  769. receiver = $('#nameInput').val();
  770. if(value == '' || receiver == '') {
  771. alert('请填写寄语');
  772. return false;
  773. }
  774. var xhr=null;
  775. try{
  776. xhr=new XMLHttpRequest();
  777. }catch(e){
  778. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  779. }
  780. xhr.open("post","news/addNews",true);
  781. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  782. xhr.send("receiver="+receiver+"&message="+value+"&userId="+window.user_info.uid);
  783. xhr.onreadystatechange=function(){
  784. if(xhr.readyState==4){
  785. if(xhr.status==200){
  786. var msg = JSON.parse(xhr.response) , href = document.location.href;
  787. if(msg.code == "ok") {
  788. window.user_info.uid = msg.data.id;
  789. window.user_info.logo = msg.data.headerPic;
  790. window.user_info.nickname = msg.data.nickName;
  791. window.user_info.namemsg = msg.data.receiver;
  792. window.user_info.textmsg = msg.data.message;
  793. $('.headimg-box img').attr("src", msg.data.headerPic);
  794. $('.user-info p').html(msg.data.nickName);
  795. $('#nameInput').val(msg.data.receiver);
  796. $('#textInput').val(msg.data.message);
  797. if(document.location.href.indexOf('?') > -1){
  798. href = document.location.href + "&uid=" + msg.data.id;
  799. } else {
  800. href = document.location.href + "?uid=" + msg.data.id;
  801. }
  802. }
  803. if(href != document.location.href){
  804. history.pushState("", "Title", href);
  805. }
  806. $("#cover").show();
  807. //if(type == 1) {
  808. setTimeout(function(){
  809. window.location.href = "http://wx.ttkuaiban.com/minigame/lottery.html";
  810. }, 10000);
  811. //}
  812. }else{
  813. console.log("错误"+xhr.status)
  814. }
  815. }
  816. }
  817. }
  818. $(".replay-btn").on("click",function(){
  819. URLParams = new Array();
  820. window.location.href = "http://wx.ttkuaiban.com/minigame/";
  821. })
  822. function hiddenCover() {
  823. $("#cover").hide();
  824. }
  825. // 自适应
  826. var stageWidth, stageHeight, stageScale;
  827. function stageBreakHandler(event) {
  828. if (stageWidth != $(".warp").width() || stageHeight != $(".warp").height()) {
  829. stageWidth = $(".warp").width();
  830. stageHeight = $(".warp").height();
  831. stageScale = stageWidth / 640;
  832. canvas.style.width = 640 * stageScale + 'px';
  833. canvas.style.height = 1040 * stageScale + 'px';
  834. }
  835. }