main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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 materialEnterAnim(dom,delay){
  192. dom.scale = 0.1;
  193. delay = delay || 0.1;
  194. var anim = new TimelineMax({ delay:delay});
  195. anim.to(dom,1.2, { scale: 1, ease: Elastic.easeOut.config(1, 0.3) })
  196. return anim;
  197. }
  198. var cutDishArr = [];
  199. // 油麦菜
  200. var ymc_iconArr = [
  201. {
  202. x: exportRoot.plate.x + exportRoot.plate.ymc_icon1.x,
  203. y: exportRoot.plate.y + exportRoot.plate.ymc_icon1.y,
  204. width: 266,
  205. height: 187,
  206. isClear: false
  207. },
  208. {
  209. x: exportRoot.plate.x + exportRoot.plate.ymc_icon2.x,
  210. y: exportRoot.plate.y + exportRoot.plate.ymc_icon2.y,
  211. width: 103,
  212. height: 118,
  213. isClear: false
  214. },
  215. {
  216. x: exportRoot.plate.x + exportRoot.plate.ymc_icon3.x,
  217. y: exportRoot.plate.y + exportRoot.plate.ymc_icon3.y,
  218. width: 371,
  219. height: 144,
  220. isClear: false
  221. },
  222. {
  223. x: exportRoot.plate.x + exportRoot.plate.ymc_icon4.x,
  224. y: exportRoot.plate.y + exportRoot.plate.ymc_icon4.y,
  225. width: 86,
  226. height: 75,
  227. isClear: false
  228. }
  229. ]
  230. // 三文鱼
  231. var swy_iconArr = [
  232. {
  233. x: exportRoot.plate.x + exportRoot.plate.hsr_icon1.x,
  234. y: exportRoot.plate.y + exportRoot.plate.hsr_icon1.y,
  235. width: 262,
  236. height: 195,
  237. isClear: false
  238. }
  239. ]
  240. // 红烧肉的位置
  241. var hsr_iconArr = [{
  242. x: exportRoot.plate.x + exportRoot.plate.hsr_icon1.x,
  243. y: exportRoot.plate.y + exportRoot.plate.hsr_icon1.y,
  244. width: 202,
  245. height: 129,
  246. isClear: false
  247. },
  248. {
  249. x: exportRoot.plate.x + exportRoot.plate.hsr_icon2.x,
  250. y: exportRoot.plate.y + exportRoot.plate.hsr_icon2.y,
  251. width: 86,
  252. height: 75,
  253. isClear: false
  254. },
  255. {
  256. x: exportRoot.plate.x + exportRoot.plate.hsr_icon3.x,
  257. y: exportRoot.plate.y + exportRoot.plate.hsr_icon3.y,
  258. width: 371,
  259. height: 144,
  260. isClear: false
  261. },
  262. {
  263. x: exportRoot.plate.x + exportRoot.plate.hsr_icon4.x,
  264. y: exportRoot.plate.y + exportRoot.plate.hsr_icon4.y,
  265. width: 103,
  266. height: 118,
  267. isClear: false
  268. }
  269. ];
  270. // 青菜豆腐的位置
  271. var qcdf_iconArr = [{
  272. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon1.x,
  273. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon1.y,
  274. width: 169,
  275. height: 320,
  276. isClear: false
  277. },
  278. {
  279. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon2.x,
  280. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon2.y,
  281. width: 207,
  282. height: 144,
  283. isClear: false
  284. },
  285. {
  286. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon3.x,
  287. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon3.y,
  288. width: 103,
  289. height: 118,
  290. isClear: false
  291. },
  292. {
  293. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon4.x,
  294. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon4.y,
  295. width: 371,
  296. height: 144,
  297. isClear: false
  298. },
  299. {
  300. x: exportRoot.plate.x + exportRoot.plate.qcdf_icon5.x,
  301. y: exportRoot.plate.y + exportRoot.plate.qcdf_icon5.y,
  302. width: 86,
  303. height: 75,
  304. isClear: false
  305. }
  306. ]
  307. // 画线
  308. var lineArr = [];
  309. var lineTimr = null;
  310. var lineShape = new createjs.Shape();
  311. function drawLine() {
  312. var value = 40;
  313. lineTimr = setInterval(function() {
  314. lineShape.graphics.clear();
  315. lineShape.graphics.setStrokeStyle(8).beginStroke("#787878");
  316. if (lineArr.length) {
  317. lineShape.graphics.moveTo(lineArr[0].x, lineArr[0].y);
  318. }
  319. for (var i = 0; i < lineArr.length; i++) {
  320. var x = lineArr[i].x;
  321. var y = lineArr[i].y;
  322. lineShape.graphics.lineTo(x, y);
  323. for (var p = 0; p < cutDishArr.length; p++) {
  324. if (x-cutDishArr[p].width/3 > cutDishArr[p].x && x < (cutDishArr[p].x + cutDishArr[p].width)) {
  325. if (y-cutDishArr[p].height/3 > cutDishArr[p].y && y < (cutDishArr[p].y + cutDishArr[p].height)) {
  326. if (cutDishArr[p].isClear == false) {
  327. cutDishArr[p].isClear = true;
  328. if(dishIndex == 0){
  329. exportRoot.plate['hsr_icon' + (p + 1)].gotoAndStop(1);
  330. }else if(dishIndex == 1){
  331. exportRoot.plate['qcdf_icon' + (p + 1)].gotoAndStop(1);
  332. }else if(dishIndex == 2){
  333. exportRoot.plate.swy_icon1.gotoAndStop(1);
  334. }else{
  335. exportRoot.plate['ymc_icon' + (p + 1)].gotoAndStop(1);
  336. }
  337. }
  338. }
  339. }
  340. }
  341. }
  342. lineArr.splice(0, 1);
  343. }, 30)
  344. }
  345. // 画线事件
  346. drawLine();
  347. exportRoot.addEventListener("mousedown", function(event) {
  348. lineArr = [];
  349. var obj = {
  350. x: event.stageX,
  351. y: event.stageY,
  352. };
  353. lineArr.push(obj);
  354. })
  355. exportRoot.addEventListener("pressmove", function(event) {
  356. if (lineArr.length >= 15) {
  357. lineArr.splice(0, 1);
  358. }
  359. var obj = {
  360. x: event.stageX,
  361. y: event.stageY,
  362. };
  363. lineArr.push(obj);
  364. })
  365. exportRoot.addEventListener("pressup", function(event) {
  366. playbowlAnim();
  367. })
  368. var dishMoveIndex = 0;
  369. // 移动菜品
  370. function dishMove(dom,x,y) {
  371. var startX = 0;
  372. var startY = 0;
  373. var domFirst = $.extend(true, {}, dom);
  374. dom.addEventListener("mousedown", function(event) {
  375. startX = event.stageX;
  376. startY = event.stageY;
  377. })
  378. dom.addEventListener("pressmove", function(event) {
  379. dom.x -= (startX - event.stageX);
  380. dom.y -= (startY - event.stageY);
  381. startX = event.stageX;
  382. startY = event.stageY;
  383. })
  384. dom.addEventListener("pressup", function(event) {
  385. if (dom.x + exportRoot.plate.x > 80 && dom.y + exportRoot.plate.y > 518) {
  386. dom.x = 190 - exportRoot.plate.x + x;
  387. dom.y = 630 - exportRoot.plate.y + y;
  388. dom.removeAllEventListeners();
  389. if(dishIndex == 0){
  390. ++dishMoveIndex;
  391. if (dishMoveIndex >= 4) {
  392. exportRoot.btn1.alpha = 1;
  393. btnAnim(exportRoot.btn1);
  394. isAllInplate();
  395. }
  396. }else if(dishIndex == 1){
  397. ++dishMoveIndex;
  398. if (dishMoveIndex >= 5) {
  399. exportRoot.btn1.alpha = 1;
  400. btnAnim(exportRoot.btn1);
  401. isAllInplate();
  402. }
  403. }else if(dishIndex == 2){
  404. exportRoot.btn1.alpha = 1;
  405. btnAnim(exportRoot.btn1);
  406. isAllInplate();
  407. }else{
  408. ++dishMoveIndex;
  409. if (dishMoveIndex >= 4) {
  410. exportRoot.btn1.alpha = 1;
  411. btnAnim(exportRoot.btn1);
  412. isAllInplate();
  413. }
  414. }
  415. } else {
  416. dom.x = domFirst.x;
  417. dom.y = domFirst.y;
  418. }
  419. })
  420. }
  421. // 菜全部到盘子里
  422. function isAllInplate() {
  423. exportRoot.btn1.addEventListener("mousedown", function() {
  424. exportRoot.btn1.removeAllEventListeners();
  425. exportRoot.btn1.alpha = 0;
  426. exportRoot.pro.alpha = 1;
  427. if(dishIndex != 2){
  428. exportRoot.bowl.alpha = 0;
  429. exportRoot.plate.alpha = 0;
  430. exportRoot.pot.alpha = 1;
  431. }else{
  432. exportRoot.plate.instance.alpha = 0;
  433. exportRoot.plate.swy_icon2.alpha = 0;
  434. }
  435. oilIconAnim();
  436. proAnim(function() {
  437. exportRoot.btn2.alpha = 1;
  438. btnAnim(exportRoot.btn2);
  439. if(dishIndex == 0){
  440. fadeInAnim(exportRoot.pot.hsr);
  441. }else if(dishIndex == 1){
  442. fadeInAnim(exportRoot.pot.qcdf);
  443. }else if(dishIndex == 3){
  444. fadeInAnim(exportRoot.pot.ymc);
  445. }
  446. });
  447. })
  448. exportRoot.btn2.addEventListener("mousedown", function() {
  449. exportRoot.btn2.removeAllEventListeners();
  450. exportRoot.btn2.alpha = 0;
  451. fadeInAnim(exportRoot.blackboard);
  452. materialEnterAnim(exportRoot.blackboard.material1,0.2);
  453. materialEnterAnim(exportRoot.blackboard.material2,0.4);
  454. materialEnterAnim(exportRoot.blackboard.material3,0.6);
  455. })
  456. exportRoot.blackboard.material1.addEventListener("mousedown", function() {
  457. exportRoot.blackboard.material1.removeAllEventListeners();
  458. exportRoot.blackboard.material2.removeAllEventListeners();
  459. exportRoot.blackboard.material3.removeAllEventListeners();
  460. exportRoot.ball1.alpha = 1;
  461. ballAnim(exportRoot.ball1);
  462. chooseType = 3;
  463. $(".poster-mode").addClass("poster-bg3");
  464. materialAnim(exportRoot.blackboard.material1, 300, 180, function() {
  465. exportRoot.blackboard.material1.x -=300;
  466. exportRoot.blackboard.material1.y -=180;
  467. // $(".shake-mode").show();
  468. shakeInit();
  469. });
  470. })
  471. exportRoot.blackboard.material2.addEventListener("mousedown", function() {
  472. exportRoot.blackboard.material1.removeAllEventListeners();
  473. exportRoot.blackboard.material2.removeAllEventListeners();
  474. exportRoot.blackboard.material3.removeAllEventListeners();
  475. exportRoot.ball2.alpha = 1;
  476. ballAnim(exportRoot.ball2);
  477. chooseType = 2;
  478. $(".poster-mode").addClass("poster-bg2");
  479. materialAnim(exportRoot.blackboard.material2, 120, 180, function() {
  480. exportRoot.blackboard.material2.x -=120;
  481. exportRoot.blackboard.material2.y -=180;
  482. // $(".shake-mode").show();
  483. shakeInit();
  484. });
  485. })
  486. exportRoot.blackboard.material3.addEventListener("mousedown", function() {
  487. exportRoot.blackboard.material1.removeAllEventListeners();
  488. exportRoot.blackboard.material2.removeAllEventListeners();
  489. exportRoot.blackboard.material3.removeAllEventListeners();
  490. console.log(exportRoot.ball3)
  491. exportRoot.ball3.alpha = 1;
  492. ballAnim(exportRoot.ball3);
  493. chooseType = 1;
  494. $(".poster-mode").addClass("poster-bg1");
  495. materialAnim(exportRoot.blackboard.material3, -30, 180, function() {
  496. exportRoot.blackboard.material3.x +=30;
  497. exportRoot.blackboard.material3.y -=180;
  498. // $(".shake-mode").show();
  499. shakeInit();
  500. });
  501. })
  502. }
  503. // 菜切完盘子上移动
  504. function playbowlAnim() {
  505. for (var i = 0; i < cutDishArr.length; i++) {
  506. if (cutDishArr[i].isClear == false) {
  507. return false;
  508. }
  509. }
  510. stage.removeChild(lineShape);
  511. clearInterval(lineTimr);
  512. exportRoot.removeAllEventListeners();
  513. bowlAnim(function() {
  514. if(dishIndex == 0){
  515. dishMove(exportRoot.plate.hsr_icon1,0,0);
  516. dishMove(exportRoot.plate.hsr_icon2,0,0);
  517. dishMove(exportRoot.plate.hsr_icon3,0,0);
  518. dishMove(exportRoot.plate.hsr_icon4,0,0);
  519. }else if(dishIndex == 1){
  520. dishMove(exportRoot.plate.qcdf_icon1,0,-80);
  521. dishMove(exportRoot.plate.qcdf_icon2,0,0);
  522. dishMove(exportRoot.plate.qcdf_icon3,0,0);
  523. dishMove(exportRoot.plate.qcdf_icon4,0,0);
  524. dishMove(exportRoot.plate.qcdf_icon5,0,0);
  525. }else if(dishIndex == 2){
  526. dishMove(exportRoot.plate.swy_icon1,120,100);
  527. }else{
  528. dishMove(exportRoot.plate.ymc_icon1,0,0);
  529. dishMove(exportRoot.plate.ymc_icon2,0,0);
  530. dishMove(exportRoot.plate.ymc_icon3,0,0);
  531. dishMove(exportRoot.plate.ymc_icon4,0,0);
  532. }
  533. });
  534. }
  535. function shakeInit() {
  536. if (window.DeviceMotionEvent) {
  537. window.addEventListener('devicemotion', deviceMotionHandler, false);
  538. } else {
  539. alert('您的手机不支持摇一摇功能!');
  540. }
  541. //获取加速度信息
  542. //通过监听上一步获取到的x, y, z 值在一定时间范围内的变化率,进行设备是否有进行晃动的判断。
  543. //而为了防止正常移动的误判,需要给该变化率设置一个合适的临界值。
  544. var SHAKE_THRESHOLD = 10000; //阈值越大,触发摇晃事件时手机摇晃的程度越剧烈
  545. var last_update = 0;
  546. var x, y, z, last_x = 0,
  547. last_y = 0,
  548. last_z = 0;
  549. function deviceMotionHandler(eventData) {
  550. var acceleration = eventData.accelerationIncludingGravity;
  551. var curTime = new Date().getTime();
  552. if ((curTime - last_update) > 10) {
  553. var diffTime = curTime - last_update;
  554. last_update = curTime;
  555. x = acceleration.x;
  556. y = acceleration.y;
  557. z = acceleration.z;
  558. var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
  559. if (speed > SHAKE_THRESHOLD) {
  560. $(".shake-mode").show();
  561. setTimeout(function(){
  562. window.removeEventListener('devicemotion', deviceMotionHandler, false);
  563. exportRoot.pot.hsr.play();
  564. exportRoot.btn3.alpha = 1;
  565. btnAnim(exportRoot.btn3);
  566. exportRoot.btn3.addEventListener("mousedown",function(){
  567. exportRoot.btn3.removeAllEventListeners();
  568. $(".poster-mode").fadeIn();
  569. })
  570. if(document.location.href.indexOf('type') == -1){
  571. var href = document.location.href + (document.location.href.indexOf('?') > -1?'&':'?') + "type=" + chooseType + "&food=" + dishIndex;
  572. history.pushState("", "Title", href);
  573. }
  574. if(dishIndex == 0){
  575. exportRoot.pot.hsr.gotoAndStop(1);
  576. }else if(dishIndex == 1){
  577. exportRoot.pot.qcdf.gotoAndStop(1);
  578. }else if(dishIndex == 2){
  579. exportRoot.bowl.oil.alpha = 0;
  580. exportRoot.plate['swy_icon1'].gotoAndStop(2);
  581. }else{
  582. exportRoot.pot.ymc.gotoAndStop(1);
  583. }
  584. $(".shake-mode").fadeOut();
  585. },3000)
  586. //dosomething
  587. $("#fire").addClass("anim-time");
  588. }else{
  589. $("#fire").removeClass("anim-time");
  590. }
  591. last_x = x;
  592. last_y = y;
  593. last_z = z;
  594. }
  595. }
  596. }
  597. //Registers the "tick" event listener.
  598. function fnStartAnimation() {
  599. stage.addChild(exportRoot, lineShape);
  600. createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED;
  601. createjs.Ticker.addEventListener("tick", stage);
  602. }
  603. fnStartAnimation();
  604. stageBreakHandler();
  605. }
  606. function getInfo() {
  607. var ua = navigator.userAgent.toLowerCase();
  608. if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  609. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  610. type = 0;
  611. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  612. +"appid=wx749c84daac654e1e&"
  613. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  614. +"response_type=code&"
  615. +"scope=snsapi_userinfo&"//snsapi_userinfo
  616. +"state=1#wechat_redirect";
  617. }
  618. if (ua.match(/WeiBo/i) == "weibo") {
  619. type = 1;
  620. url = "https://api.weibo.com/oauth2/authorize?"
  621. +"client_id=2141531565&"
  622. +"response_type=code&"
  623. +"redirect_uri=http://wx.ttkuaiban.com/minigame/index.html"
  624. }
  625. } else {
  626. var ua = navigator.userAgent.toLowerCase();
  627. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  628. type = 0;
  629. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  630. +"appid=wx749c84daac654e1e&"
  631. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  632. +"response_type=code&"
  633. +"scope=snsapi_userinfo&"//snsapi_userinfo
  634. +"state=1#wechat_redirect";
  635. }
  636. }
  637. if(URLParams['uid']) {
  638. $('#nameInput').hide();
  639. $('#nameText').show();
  640. $('#textInput').hide();
  641. $('#text').show();
  642. $('.replay-btn').hide();
  643. $('.secret-btn').hide();
  644. chooseType = URLParams['type'];
  645. dishType = URLParams['food'];
  646. $(".poster-mode").addClass("poster-bg" + chooseType);
  647. if(dishType == 0){
  648. $('#poster').attr('src','./img/poster/hsr.png');
  649. }else if(dishType == 1){
  650. $('#poster').attr('src','./img/poster/qcdf.png');
  651. }else if(dishType == 2){
  652. $('#poster').attr('src','./img/poster/swy.png');
  653. }else{
  654. $('#poster').attr('src','./img/poster/ymc.png');
  655. }
  656. getMsg();
  657. $(".poster-mode").fadeIn();
  658. } else {
  659. $('#nameInput').show();
  660. $('#nameText').hide();
  661. $('#textInput').show();
  662. $('#text').hide();
  663. $('.replay-btn').show();
  664. $('.secret-btn').show();
  665. init();
  666. getMsg();
  667. }
  668. }
  669. // 获取登陆信息
  670. function getMsg(){
  671. if(URLParams['uid'] || localStorage.userId){
  672. if(URLParams['uid']) {
  673. var uid = URLParams['uid'];
  674. var xhr=null;
  675. try{
  676. xhr=new XMLHttpRequest();
  677. }catch(e){
  678. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  679. }
  680. xhr.open("post","news/show",true);
  681. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  682. xhr.send("id="+uid);
  683. xhr.onreadystatechange=function(){
  684. if(xhr.readyState==4){
  685. if(xhr.status==200){
  686. var msg = JSON.parse(xhr.response);
  687. if(msg.code == "ok") {
  688. window.user_info.uid = msg.data.id;
  689. window.user_info.logo = msg.data.headerPic;
  690. window.user_info.nickname = msg.data.nickName;
  691. window.user_info.namemsg = msg.data.message;
  692. window.user_info.textmsg = msg.data.message;
  693. $('.headimg-box img').attr("src", msg.data.headerPic);
  694. $('.user-info p').html(msg.data.nickName);
  695. $('#nameText').html(msg.data.receiver);
  696. $('#text').html(msg.data.message);
  697. }
  698. }else{
  699. console.log("错误"+xhr.status)
  700. }
  701. }
  702. }
  703. } else {
  704. window.user_info.uid = localStorage.userId;
  705. window.user_info.logo = localStorage.userPic;
  706. window.user_info.nickname = localStorage.userName;
  707. $('.headimg-box img').attr("src", localStorage.userPic);
  708. $('.user-info p').html(localStorage.userName);
  709. }
  710. }else {
  711. if(URLParams['code']){
  712. var code = URLParams['code'];
  713. var xhr=null;
  714. try{
  715. xhr=new XMLHttpRequest();
  716. }catch(e){
  717. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  718. }
  719. xhr.open("post","user/weiXinLogin",true);
  720. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  721. xhr.send("code="+code+"&type="+type);
  722. xhr.onreadystatechange=function(){
  723. if(xhr.readyState==4){
  724. if(xhr.status==200){
  725. var msg = JSON.parse(xhr.response);
  726. if(msg.code == "ok") {
  727. window.user_info.uid = msg.data.id;
  728. localStorage.userId = msg.data.id;
  729. localStorage.userPic = msg.data.headerPic;
  730. localStorage.userName = msg.data.nickName;
  731. window.user_info.logo = msg.data.headerPic;
  732. window.user_info.nickname = msg.data.nickName;
  733. $('.headimg-box img').attr("src", msg.data.headerPic);
  734. $('.user-info p').html(msg.data.nickName);
  735. }
  736. }else{
  737. console.log("错误"+xhr.status)
  738. }
  739. }
  740. }
  741. } else {
  742. window.location.href = url;
  743. }
  744. }
  745. }
  746. function saveText() {
  747. var value = $('#textInput').val(),
  748. receiver = $('#nameInput').val();
  749. if(value == '' || receiver == '') {
  750. alert('请填写寄语');
  751. return false;
  752. }
  753. var xhr=null;
  754. try{
  755. xhr=new XMLHttpRequest();
  756. }catch(e){
  757. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  758. }
  759. xhr.open("post","news/addNews",true);
  760. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  761. xhr.send("receiver="+receiver+"&message="+value+"&userId="+window.user_info.uid);
  762. xhr.onreadystatechange=function(){
  763. if(xhr.readyState==4){
  764. if(xhr.status==200){
  765. var msg = JSON.parse(xhr.response) , href = document.location.href;
  766. if(msg.code == "ok") {
  767. window.user_info.uid = msg.data.id;
  768. window.user_info.logo = msg.data.headerPic;
  769. window.user_info.nickname = msg.data.nickName;
  770. window.user_info.namemsg = msg.data.receiver;
  771. window.user_info.textmsg = msg.data.message;
  772. $('.headimg-box img').attr("src", msg.data.headerPic);
  773. $('.user-info p').html(msg.data.nickName);
  774. $('#nameInput').val(msg.data.receiver);
  775. $('#textInput').val(msg.data.message);
  776. if(document.location.href.indexOf('?') > -1){
  777. href = document.location.href + "&uid=" + msg.data.id;
  778. } else {
  779. href = document.location.href + "?uid=" + msg.data.id;
  780. }
  781. }
  782. if(href != document.location.href){
  783. history.pushState("", "Title", href);
  784. }
  785. $("#cover").show();
  786. //if(type == 1) {
  787. setTimeout(function(){
  788. window.location.href = "http://wx.ttkuaiban.com/minigame/lottery.html";
  789. }, 10000);
  790. //}
  791. }else{
  792. console.log("错误"+xhr.status)
  793. }
  794. }
  795. }
  796. }
  797. $(".replay-btn").on("click",function(){
  798. URLParams = new Array();
  799. window.location.href = "http://wx.ttkuaiban.com/minigame/";
  800. })
  801. function hiddenCover() {
  802. $("#cover").hide();
  803. }
  804. // 自适应
  805. var stageWidth, stageHeight, stageScale;
  806. function stageBreakHandler(event) {
  807. if (stageWidth != $(".warp").width() || stageHeight != $(".warp").height()) {
  808. stageWidth = $(".warp").width();
  809. stageHeight = $(".warp").height();
  810. stageScale = stageWidth / 640;
  811. canvas.style.width = 640 * stageScale + 'px';
  812. canvas.style.height = 1040 * stageScale + 'px';
  813. }
  814. }