game.min.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. var VERSION = "1.1.9";
  2. var viewWidth = view.viewSize.width;
  3. var viewHeight = view.viewSize.height;
  4. var windowWidth = viewWidth;
  5. var windowHeight = viewHeight;
  6. var loading =true;
  7. if (windowWidth > windowHeight / 4 * 3) {
  8. windowWidth = windowHeight / 4 * 3
  9. }
  10. var barWidth = windowWidth / 1.3;
  11. var barHeight = windowHeight / 14;
  12. var slideWidth = windowWidth;
  13. var slideHeight = windowHeight / 5;
  14. var characterWidth = windowWidth / 40;
  15. var characterHeight = windowHeight / 80;
  16. var pinRadius = windowWidth / 180;
  17. var hintLineLength = windowHeight / 8;
  18. var slideRadius = windowHeight / 32;
  19. var timerTextPosY = windowHeight / 5.5;
  20. var timerTextFontSize = windowHeight / 15;
  21. var helpTextFontSize = windowHeight / 30;
  22. var rankTextFontSize = windowHeight / 30;
  23. var versionTextFontSize = windowHeight / 70;
  24. var menuWidth = windowWidth / 1.1;
  25. var menuHeight = windowHeight / 2.5;
  26. var menuStrokeWidth = windowHeight / 100;
  27. var slideStrokeWidth = windowHeight / 200;
  28. var replayWidth = windowHeight / 25;
  29. var replayPosY = windowHeight / 2;
  30. var menuButtonWidth = windowHeight / 10;
  31. var menuButtonHeight = windowHeight / 15;
  32. var helpWidth = windowWidth / 1.5;
  33. var helpHeight = windowHeight / 2;
  34. var arrowWidth = windowWidth / 8;
  35. var arrowHeight = windowWidth / 3.5;
  36. var arrowTextFontSize = windowHeight / 30;
  37. var tutorialWidth = windowWidth / 3;
  38. var tutorialHeight = windowWidth / 10;
  39. var tutorialStrokeWidth = windowHeight / 200;
  40. var tutorialTextFontSize = windowHeight / 40;
  41. var windowWidth2 = windowWidth / 2;
  42. var windowHeight2 = windowHeight / 2;
  43. var viewWidth2 = viewWidth / 2;
  44. var viewHeight2 = viewHeight / 2;
  45. var barWidth2 = barWidth / 2;
  46. var barHeight2 = barHeight / 2;
  47. var slideWidth2 = slideWidth / 2;
  48. var slideHeight2 = slideHeight / 2;
  49. var characterWidth2 = characterWidth / 2;
  50. var characterHeight2 = characterHeight / 2;
  51. var pinRadius2 = pinRadius / 2;
  52. var hintLineLength2 = hintLineLength / 2;
  53. var menuWidth2 = menuWidth / 2;
  54. var menuHeight2 = menuHeight / 2;
  55. var menuStrokeWidth2 = menuStrokeWidth / 2;
  56. var menuButtonWidth2 = menuButtonWidth / 2;
  57. var menuButtonHeight2 = menuButtonHeight / 2;
  58. var helpWidth2 = helpWidth / 2;
  59. var helpHeight2 = helpHeight / 2;
  60. var arrowWidth2 = arrowWidth / 2;
  61. var arrowHeight2 = arrowHeight / 2;
  62. var tutorialWidth2 = tutorialWidth / 2;
  63. var tutorialHeight2 = tutorialHeight / 2;
  64. var windowSize = new Size(windowWidth - 1, windowHeight - 1);
  65. var barSize = new Size(barWidth, barHeight);
  66. var slideSize = new Size(slideWidth, slideHeight);
  67. var characterSize = new Size(characterWidth, characterHeight);
  68. var menuSize = new Size(menuWidth, menuHeight);
  69. var menuButtonSize = new Size(menuButtonWidth, menuButtonHeight);
  70. var helpSize = new Size(helpWidth, helpHeight);
  71. var tutorialSize = new Size(tutorialWidth, tutorialHeight);
  72. var menuButtonBiasX = windowHeight / 6;
  73. var menuButtonBiasY = windowHeight / 4.8;
  74. var maxRandomBias = windowHeight / 20;
  75. var minRandomBias = windowHeight / 200;
  76. var helpBiasY = windowHeight / 3;
  77. var rankBiasY = 0;
  78. var arrowBiasX = windowWidth / 20;
  79. var versionBiasX = windowWidth / 5;
  80. var tutorialBiasY = windowHeight / 3.3;
  81. var minOmega = .1;
  82. var slideFactor = .5;
  83. var alphaFactor = 200 / windowWidth;
  84. var rankTextFirstLine = "感谢您的分享\n\n";
  85. var shared = getCookie("shared").length;
  86. var isiphone = getCookie("isiphone").length;
  87. var times_played = parseInt(getCookie("times_played"));
  88. if (!times_played) {
  89. times_played = 0
  90. }
  91. if (!shared || isiphone) {
  92. rankTextFirstLine = "\n"
  93. }
  94. if (!getCookie("uuid")) {
  95. setCookie("uuid", uuid())
  96. }
  97. var nameSubmitted = false;
  98. var timer = 0;
  99. var percentage = "0%";
  100. var slideX = 0;
  101. var alpha = 0;
  102. var omega = 0;
  103. var angle = 0;
  104. var status = 0;
  105. var loadedAd = false;
  106. var randomBias = (Math.random() - .5) * maxRandomBias;
  107. if (randomBias < 0) {
  108. randomBias -= minRandomBias
  109. } else {
  110. randomBias += minRandomBias
  111. }
  112. var biasX = randomBias;
  113. var mouseX = windowWidth2;
  114. var positionList = Array();
  115. console.log(viewWidth);
  116. console.log(viewHeight);
  117. console.log(barSize.width);
  118. console.log(barSize.height);
  119. console.log(characterSize.width);
  120. console.log(characterSize.height);
  121. console.log(viewWidth2 - characterWidth2 + biasX);
  122. console.log(viewHeight2 - characterHeight - barHeight2);
  123. try {
  124. var back_rect = new Path.Rectangle(new Point(1, 1), windowSize);
  125. back_rect.fillColor = "white"
  126. } catch(err) {
  127. $.ajax({
  128. type: "POST",
  129. url: "balance",
  130. data: {
  131. unsupport: 1,
  132. UA: navigator.appVersion,
  133. cookies: document.cookie
  134. }
  135. });
  136. alert("抱歉,本游戏暂不支持您的浏览器。")
  137. }
  138. var rect = new Path.Rectangle(new Point(viewWidth2 - barWidth2, viewHeight2 - barHeight2), barSize);
  139. rect.fillColor = "black";
  140. rect.transformContent = false;
  141. var pin = new Shape.Circle(new Point(viewWidth2, viewHeight2), pinRadius);
  142. pin.fillColor = "grey";
  143. var hintLine = new Path.Line(new Point(viewWidth2, viewHeight2 - hintLineLength), new Point(viewWidth2, viewHeight2));
  144. hintLine.strokeColor = "red";
  145. hintLine.strokeWidth = 1;
  146. var character = new Path.Rectangle(new Point(viewWidth2 - characterWidth2 + biasX, viewHeight2 - characterHeight - barHeight2), characterSize);
  147. character.transformContent = false;
  148. character.fillColor = "blue";
  149. var slideBack = new Shape.Rectangle(new Point(viewWidth2 - slideWidth2, viewHeight - slideHeight), slideSize, new Size(slideRadius, slideRadius));
  150. slideBack.opacity = 0;
  151. var slideCircle = new Shape.Circle(new Point(viewWidth2, viewHeight - slideHeight2), slideHeight2);
  152. var slideGroup = new Group(slideCircle, slideBack);
  153. slideGroup.clipped = true;
  154. slideBack.fillColor = {
  155. gradient: {
  156. stops: ["blue", "white", "blue"]
  157. },
  158. origin: new Point( - slideWidth2, 0),
  159. destination: new Point(slideWidth2, 0)
  160. };
  161. var slideStroke = new Shape.Rectangle(new Point(viewWidth2 - slideWidth2, viewHeight - slideHeight), slideSize, new Size(slideRadius, slideRadius));
  162. slideStroke.strokeWidth = slideStrokeWidth;
  163. slideStroke.strokeColor = "gray";
  164. var timerText = new PointText({
  165. point: [viewWidth2, timerTextPosY],
  166. justification: "center",
  167. fillColor: "black",
  168. fontSize: timerTextFontSize
  169. });
  170. timerText.fillColor = "black";
  171. var versionText = new PointText({
  172. point: [viewWidth2, viewHeight - .5 * versionTextFontSize - slideStrokeWidth],
  173. justification: "center",
  174. fillColor: "black",
  175. fontSize: versionTextFontSize
  176. });
  177. versionText.content = "点击本框,调整平衡";
  178. var helpBox = new Shape.Rectangle({
  179. point: [viewWidth2 - helpWidth2, helpBiasY - helpHeight2],
  180. size: helpSize,
  181. strokeColor: "black",
  182. fillColor: "white",
  183. strokeJoin: "round",
  184. strokeWidth: menuStrokeWidth
  185. });
  186. var helpText = new PointText({
  187. point: [viewWidth2, helpBiasY - 3.5 * helpTextFontSize],
  188. justification: "center",
  189. fillColor: "black",
  190. fontSize: helpTextFontSize
  191. });
  192. helpText.content = "强迫症矫正棍\n ——你以为你能调平?\n\n点击下方的控制条来\n控制小滑块,以保持\n矫正棍的平衡。\n\n点此开始";
  193. var helpGroup = new Group(helpBox, helpText);
  194. helpBox.onMouseDown = function(event) {
  195. helpGroup.visible = false;
  196. tutorialGroup.visible = false;
  197. status = 1
  198. };
  199. helpText.onMouseDown = function(event) {
  200. helpGroup.visible = false;
  201. tutorialGroup.visible = false;
  202. status = 1
  203. };
  204. var menuBox = new Shape.Rectangle({
  205. point: [viewWidth2 - menuWidth2, viewHeight2 - menuHeight2],
  206. size: menuSize,
  207. strokeColor: "black",
  208. fillColor: "white",
  209. strokeJoin: "round",
  210. strokeWidth: menuStrokeWidth
  211. });
  212. var replayButton = new Path.Circle(new Point(viewWidth2 - menuButtonBiasX, viewHeight2 + menuButtonBiasY), menuButtonWidth2);
  213. replayButton.fillColor = "white";
  214. var replaySVG = new Path.Circle(new Point(viewWidth2 - menuButtonBiasX, viewHeight2 + menuButtonBiasY), menuButtonWidth2);
  215. replaySVG = replaySVG.split(replaySVG.length * .55);
  216. replaySVG.strokeColor = "red";
  217. replaySVG.strokeWidth = menuStrokeWidth;
  218. replaySVG.strokeCap = "round";
  219. replaySVG.firstSegment.point -= [menuStrokeWidth, menuStrokeWidth2];
  220. replaySVG.lastSegment.remove();
  221. replaySVG.lastSegment.point += [menuStrokeWidth2, menuStrokeWidth2];
  222. var shareButton = new Path.Rectangle(new Point(viewWidth2 + menuButtonBiasX - menuButtonWidth2, viewHeight2 + menuButtonWidth2 - menuButtonHeight + menuButtonBiasY), menuButtonSize);
  223. shareButton.fillColor = "white";
  224. var shareSVG = new Path.Rectangle(new Point(viewWidth2 + menuButtonBiasX - menuButtonWidth2, viewHeight2 + menuButtonWidth2 - menuButtonHeight + menuButtonBiasY), menuButtonSize);
  225. shareSVG.strokeColor = "blue";
  226. shareSVG.strokeWidth = menuStrokeWidth;
  227. var shareSVG1 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY));
  228. var shareSVG2 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX - menuButtonHeight2, viewHeight2 - menuButtonHeight2 + menuButtonBiasY));
  229. var shareSVG3 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX + menuButtonHeight2, viewHeight2 - menuButtonHeight2 + menuButtonBiasY));
  230. shareSVG1.strokeColor = "blue";
  231. shareSVG1.strokeWidth = menuStrokeWidth;
  232. shareSVG2.strokeColor = "blue";
  233. shareSVG2.strokeWidth = menuStrokeWidth;
  234. shareSVG2.strokeCap = "round";
  235. shareSVG3.strokeColor = "blue";
  236. shareSVG3.strokeWidth = menuStrokeWidth;
  237. shareSVG3.strokeCap = "round";
  238. var rankText = new PointText({
  239. point: [viewWidth2, viewHeight2 + rankBiasY - 2.5 * rankTextFontSize],
  240. justification: "center",
  241. fillColor: "black",
  242. fontSize: rankTextFontSize
  243. });
  244. rankText.content = "";
  245. var menuGroup = new Group(menuBox, replayButton, replaySVG, shareButton, shareSVG, shareSVG1, shareSVG2, shareSVG3, rankText);
  246. menuGroup.visible = false;
  247. replayButton.onMouseDown = function(event) {
  248. event.preventDefault();
  249. init()
  250. };
  251. shareButton.onMouseDown = function(event) {
  252. event.preventDefault();
  253. dp_share();
  254. };
  255. var tutorialBox = new Shape.Rectangle({
  256. point: [viewWidth2 - tutorialWidth2, viewHeight2 - tutorialHeight2 + tutorialBiasY],
  257. size: tutorialSize,
  258. strokeColor: "black",
  259. fillColor: "white",
  260. strokeJoin: "round",
  261. strokeWidth: tutorialStrokeWidth
  262. });
  263. var tutorialText = new PointText({
  264. point: [viewWidth2, viewHeight2 + tutorialBiasY+5],
  265. justification: "center",
  266. fillColor: "black",
  267. fontSize: tutorialTextFontSize
  268. });
  269. tutorialText.content = "更多游戏";
  270. var tutorialGroup = new Group(tutorialBox, tutorialText);
  271. tutorialGroup.visible = true;
  272. tutorialBox.onMouseDown = function(event) {
  273. clickMore();
  274. };
  275. tutorialText.onMouseDown = function(event) {
  276. clickMore();
  277. };
  278. var arrowSVG = new Path(new Segment(new Point(viewWidth - arrowWidth - arrowBiasX, arrowHeight), null, new Point(0, -arrowHeight2)), new Segment(new Point(viewWidth - arrowBiasX, 0), null, null));
  279. arrowSVG.strokeColor = "blue";
  280. arrowSVG.strokeWidth = menuStrokeWidth;
  281. var arrowText = new PointText({
  282. point: [viewWidth - arrowWidth - arrowBiasX, arrowHeight + arrowTextFontSize],
  283. justification: "center",
  284. fillColor: "black",
  285. fontSize: arrowTextFontSize
  286. });
  287. arrowText.content = "分享到朋友圈";
  288. var arrowGroup = new Group(arrowSVG, arrowText);
  289. arrowGroup.visible = false;
  290. slideDown = false;
  291. slideBack.onMouseDown = function(event) {
  292. event.preventDefault();
  293. slideDown = true;
  294. mouseX = event.point.x;
  295. slideX = event.point.x - viewWidth2
  296. };
  297. slideBack.onMouseMove = function(event) {
  298. mouseX = event.point.x;
  299. slideX = event.point.x - viewWidth2
  300. };
  301. slideBack.onMouseUp = function(event) {
  302. slideDown = false
  303. };
  304. slideBack.onMouseLeave = function(event) {
  305. slideDown = false
  306. };
  307. function init() {
  308. timer = 0;
  309. percentage = "0%";
  310. slideX = 0;
  311. alpha = 0;
  312. omega = 0;
  313. angle = 0;
  314. status = 1;
  315. randomBias = (Math.random() - .5) * maxRandomBias;
  316. if (randomBias < 0) {
  317. randomBias -= minRandomBias
  318. } else {
  319. randomBias += minRandomBias
  320. }
  321. biasX = randomBias;
  322. menuGroup.visible = false;
  323. tutorialGroup.visible = false;
  324. arrowGroup.visible = false;
  325. versionText.visible = true;
  326. hintLine.visible = true;
  327. hintLine.dashArray = [];
  328. HideContent("desktop-ad");
  329. document.title = "强迫症矫正棍——你以为你能调平?"
  330. }
  331. function uuid(len, radix) {
  332. var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),
  333. uuid = [],
  334. i;
  335. radix = radix || chars.length;
  336. if (len) {
  337. for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]
  338. } else {
  339. var r;
  340. uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
  341. uuid[14] = "4";
  342. for (i = 0; i < 36; i++) {
  343. if (!uuid[i]) {
  344. r = 0 | Math.random() * 16;
  345. uuid[i] = chars[i == 19 ? r & 3 | 8 : r]
  346. }
  347. }
  348. }
  349. return uuid.join("")
  350. }
  351. function encourage(timer) {
  352. if (timer < 10) {
  353. return "\n“我一定能把它调平!”"
  354. } else if (timer < 30) {
  355. return "\n“有一种把它调平的感觉在心中发芽。”"
  356. } else if (timer < 60) {
  357. return "\n“呼,好像刚刚自学完成刚体力学!”"
  358. } else if (timer < 120) {
  359. return "\n“这成绩要是分享一下的话... :D”"
  360. } else {
  361. return "\n“我已经知道了,这个世界不是完美的”"
  362. }
  363. }
  364. function fillRankText(percentage) {
  365. if (!isiphone && !shared) {
  366. rankText.content = "别自己刷啦,分享到朋友圈\n看下好友的强迫症如何?\n"
  367. } else {
  368. rankText.content = rankTextFirstLine
  369. }
  370. if (!percentage) {
  371. var timerInt = parseInt(timer);
  372. percentage = (positionList[timerInt + 1] - positionList[timerInt]) * (timer - timerInt) + positionList[timerInt];
  373. percentage = (percentage * 100).toFixed(2) + "%"
  374. }
  375. rankText.content += "\n强迫症矫正棍上坚持了" + timer.toFixed(2) + "秒";
  376. rankText.content += encourage(timer);
  377. dp_submitScore(timer.toFixed(2));
  378. }
  379. function onFrame(event) {
  380. if (status === 0) {
  381. if (!helpText.visible) {
  382. helpText.visible = true
  383. }
  384. if (loading) {
  385. loading = false;
  386. HideContent("inputpage")
  387. }
  388. } else if (status === 1) {
  389. if (event.delta > 5) {
  390. event.delta = 5
  391. }
  392. if (slideDown) {
  393. slideBack.opacity = 1;
  394. slideCircle.position.x = mouseX
  395. } else {
  396. slideBack.opacity = 0
  397. }
  398. timerText.content = timer.toFixed(2);
  399. timerText.content += "''";
  400. if (timer > 20 && !hintLine.dashArray.length) {
  401. hintLine.dashArray = [1, 4]
  402. }
  403. if (timer > 30 && hintLine.visible && !shared) {
  404. hintLine.visible = false
  405. }
  406. angleArc = angle / 180 * Math.PI;
  407. cos = Math.cos(angleArc);
  408. sin = Math.sin(angleArc);
  409. tan = Math.tan(angleArc);
  410. realBiasX = biasX * cos + sin * barHeight2 + sin * characterHeight2;
  411. realBiasY = characterHeight2 * cos - biasX * sin + barHeight2 * cos;
  412. character.position = new Point(viewWidth2 + realBiasX, viewHeight2 - realBiasY);
  413. if (slideDown) {
  414. newBiasX = biasX + slideX * event.delta * slideFactor;
  415. if (newBiasX < barWidth2 && newBiasX > -barWidth2) {
  416. biasX = newBiasX
  417. }
  418. }
  419. timer += event.delta;
  420. alpha += event.delta * realBiasX * alphaFactor;
  421. omega += event.delta * alpha;
  422. if (omega < minOmega && omega > 0 && alpha < 0) {
  423. omega = minOmega
  424. } else if (omega > -minOmega && omega < 0 && alpha > 0) {
  425. omega = -minOmega
  426. }
  427. deltaAngle = event.delta * omega;
  428. angle += deltaAngle;
  429. rect.rotation = angle;
  430. character.rotation = angle;
  431. if (angle < -90 || angle > 90) {
  432. times_played = parseInt(getCookie("times_played"));
  433. if (!times_played) {
  434. times_played = 0
  435. }
  436. setCookie("times_played", times_played + 1);
  437. status = 2;
  438. slideBack.opacity = 0;
  439. if (positionList.length) {
  440. fillRankText();
  441. } else {
  442. fillRankText();
  443. }
  444. tutorialGroup.visible = true;
  445. }
  446. } else if (status == 2) {
  447. if (!menuGroup.visible) {
  448. timerText.content = timer.toFixed(2);
  449. timerText.content += "''";
  450. if (times_played >= 1 && !(times_played % 5)) {
  451. //ShowContent("desktop-ad")
  452. }
  453. menuGroup.opacity = 0;
  454. menuGroup.visible = true;
  455. versionText.opacity = 0;
  456. versionText.visible = true;
  457. if (!shared) {
  458. arrowGroup.opacity = 0;
  459. arrowGroup.visible = true
  460. }
  461. if (times_played < 20) {
  462. tutorialGroup.opacity = 0;
  463. tutorialGroup.visible = true
  464. }
  465. }
  466. if (menuGroup.opacity < 1) {
  467. opacity = menuGroup.opacity += 5 * event.delta;
  468. if (opacity > 1) {
  469. opacity = 1
  470. }
  471. menuGroup.opacity = opacity;
  472. versionText.opacity = opacity;
  473. if (!shared) {
  474. arrowGroup.opacity = opacity
  475. }
  476. if (times_played < 20) {
  477. tutorialGroup.opacity = opacity
  478. }
  479. }
  480. tutorialGroup.visible = true;
  481. }
  482. }
  483. function HideContent(d) {
  484. $('#' + d).hide();
  485. }
  486. function ShowContent(d) {
  487. $('#' + d).show(1000);
  488. }