main.js 32 KB

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