var VERSION = "1.1.9"; var viewWidth = view.viewSize.width; var viewHeight = view.viewSize.height; var windowWidth = viewWidth; var windowHeight = viewHeight; var loading =true; if (windowWidth > windowHeight / 4 * 3) { windowWidth = windowHeight / 4 * 3 } var barWidth = windowWidth / 1.3; var barHeight = windowHeight / 14; var slideWidth = windowWidth; var slideHeight = windowHeight / 5; var characterWidth = windowWidth / 40; var characterHeight = windowHeight / 80; var pinRadius = windowWidth / 180; var hintLineLength = windowHeight / 8; var slideRadius = windowHeight / 32; var timerTextPosY = windowHeight / 5.5; var timerTextFontSize = windowHeight / 15; var helpTextFontSize = windowHeight / 30; var rankTextFontSize = windowHeight / 30; var versionTextFontSize = windowHeight / 70; var menuWidth = windowWidth / 1.1; var menuHeight = windowHeight / 2.5; var menuStrokeWidth = windowHeight / 100; var slideStrokeWidth = windowHeight / 200; var replayWidth = windowHeight / 25; var replayPosY = windowHeight / 2; var menuButtonWidth = windowHeight / 10; var menuButtonHeight = windowHeight / 15; var helpWidth = windowWidth / 1.5; var helpHeight = windowHeight / 2; var arrowWidth = windowWidth / 8; var arrowHeight = windowWidth / 3.5; var arrowTextFontSize = windowHeight / 30; var tutorialWidth = windowWidth / 3; var tutorialHeight = windowWidth / 10; var tutorialStrokeWidth = windowHeight / 200; var tutorialTextFontSize = windowHeight / 40; var windowWidth2 = windowWidth / 2; var windowHeight2 = windowHeight / 2; var viewWidth2 = viewWidth / 2; var viewHeight2 = viewHeight / 2; var barWidth2 = barWidth / 2; var barHeight2 = barHeight / 2; var slideWidth2 = slideWidth / 2; var slideHeight2 = slideHeight / 2; var characterWidth2 = characterWidth / 2; var characterHeight2 = characterHeight / 2; var pinRadius2 = pinRadius / 2; var hintLineLength2 = hintLineLength / 2; var menuWidth2 = menuWidth / 2; var menuHeight2 = menuHeight / 2; var menuStrokeWidth2 = menuStrokeWidth / 2; var menuButtonWidth2 = menuButtonWidth / 2; var menuButtonHeight2 = menuButtonHeight / 2; var helpWidth2 = helpWidth / 2; var helpHeight2 = helpHeight / 2; var arrowWidth2 = arrowWidth / 2; var arrowHeight2 = arrowHeight / 2; var tutorialWidth2 = tutorialWidth / 2; var tutorialHeight2 = tutorialHeight / 2; var windowSize = new Size(windowWidth - 1, windowHeight - 1); var barSize = new Size(barWidth, barHeight); var slideSize = new Size(slideWidth, slideHeight); var characterSize = new Size(characterWidth, characterHeight); var menuSize = new Size(menuWidth, menuHeight); var menuButtonSize = new Size(menuButtonWidth, menuButtonHeight); var helpSize = new Size(helpWidth, helpHeight); var tutorialSize = new Size(tutorialWidth, tutorialHeight); var menuButtonBiasX = windowHeight / 6; var menuButtonBiasY = windowHeight / 4.8; var maxRandomBias = windowHeight / 20; var minRandomBias = windowHeight / 200; var helpBiasY = windowHeight / 3; var rankBiasY = 0; var arrowBiasX = windowWidth / 20; var versionBiasX = windowWidth / 5; var tutorialBiasY = windowHeight / 3.3; var minOmega = .1; var slideFactor = .5; var alphaFactor = 200 / windowWidth; var rankTextFirstLine = "感谢您的分享\n\n"; var shared = getCookie("shared").length; var isiphone = getCookie("isiphone").length; var times_played = parseInt(getCookie("times_played")); if (!times_played) { times_played = 0 } if (!shared || isiphone) { rankTextFirstLine = "\n" } if (!getCookie("uuid")) { setCookie("uuid", uuid()) } var nameSubmitted = false; var timer = 0; var percentage = "0%"; var slideX = 0; var alpha = 0; var omega = 0; var angle = 0; var status = 0; var loadedAd = false; var randomBias = (Math.random() - .5) * maxRandomBias; if (randomBias < 0) { randomBias -= minRandomBias } else { randomBias += minRandomBias } var biasX = randomBias; var mouseX = windowWidth2; var positionList = Array(); console.log(viewWidth); console.log(viewHeight); console.log(barSize.width); console.log(barSize.height); console.log(characterSize.width); console.log(characterSize.height); console.log(viewWidth2 - characterWidth2 + biasX); console.log(viewHeight2 - characterHeight - barHeight2); try { var back_rect = new Path.Rectangle(new Point(1, 1), windowSize); back_rect.fillColor = "white" } catch(err) { $.ajax({ type: "POST", url: "balance", data: { unsupport: 1, UA: navigator.appVersion, cookies: document.cookie } }); alert("抱歉,本游戏暂不支持您的浏览器。") } var rect = new Path.Rectangle(new Point(viewWidth2 - barWidth2, viewHeight2 - barHeight2), barSize); rect.fillColor = "black"; rect.transformContent = false; var pin = new Shape.Circle(new Point(viewWidth2, viewHeight2), pinRadius); pin.fillColor = "grey"; var hintLine = new Path.Line(new Point(viewWidth2, viewHeight2 - hintLineLength), new Point(viewWidth2, viewHeight2)); hintLine.strokeColor = "red"; hintLine.strokeWidth = 1; var character = new Path.Rectangle(new Point(viewWidth2 - characterWidth2 + biasX, viewHeight2 - characterHeight - barHeight2), characterSize); character.transformContent = false; character.fillColor = "blue"; var slideBack = new Shape.Rectangle(new Point(viewWidth2 - slideWidth2, viewHeight - slideHeight), slideSize, new Size(slideRadius, slideRadius)); slideBack.opacity = 0; var slideCircle = new Shape.Circle(new Point(viewWidth2, viewHeight - slideHeight2), slideHeight2); var slideGroup = new Group(slideCircle, slideBack); slideGroup.clipped = true; slideBack.fillColor = { gradient: { stops: ["blue", "white", "blue"] }, origin: new Point( - slideWidth2, 0), destination: new Point(slideWidth2, 0) }; var slideStroke = new Shape.Rectangle(new Point(viewWidth2 - slideWidth2, viewHeight - slideHeight), slideSize, new Size(slideRadius, slideRadius)); slideStroke.strokeWidth = slideStrokeWidth; slideStroke.strokeColor = "gray"; var timerText = new PointText({ point: [viewWidth2, timerTextPosY], justification: "center", fillColor: "black", fontSize: timerTextFontSize }); timerText.fillColor = "black"; var versionText = new PointText({ point: [viewWidth2, viewHeight - .5 * versionTextFontSize - slideStrokeWidth], justification: "center", fillColor: "black", fontSize: versionTextFontSize }); versionText.content = "点击本框,调整平衡"; var helpBox = new Shape.Rectangle({ point: [viewWidth2 - helpWidth2, helpBiasY - helpHeight2], size: helpSize, strokeColor: "black", fillColor: "white", strokeJoin: "round", strokeWidth: menuStrokeWidth }); var helpText = new PointText({ point: [viewWidth2, helpBiasY - 3.5 * helpTextFontSize], justification: "center", fillColor: "black", fontSize: helpTextFontSize }); helpText.content = "强迫症矫正棍\n ——你以为你能调平?\n\n点击下方的控制条来\n控制小滑块,以保持\n矫正棍的平衡。\n\n点此开始"; var helpGroup = new Group(helpBox, helpText); helpBox.onMouseDown = function(event) { helpGroup.visible = false; tutorialGroup.visible = false; status = 1 }; helpText.onMouseDown = function(event) { helpGroup.visible = false; tutorialGroup.visible = false; status = 1 }; var menuBox = new Shape.Rectangle({ point: [viewWidth2 - menuWidth2, viewHeight2 - menuHeight2], size: menuSize, strokeColor: "black", fillColor: "white", strokeJoin: "round", strokeWidth: menuStrokeWidth }); var replayButton = new Path.Circle(new Point(viewWidth2 - menuButtonBiasX, viewHeight2 + menuButtonBiasY), menuButtonWidth2); replayButton.fillColor = "white"; var replaySVG = new Path.Circle(new Point(viewWidth2 - menuButtonBiasX, viewHeight2 + menuButtonBiasY), menuButtonWidth2); replaySVG = replaySVG.split(replaySVG.length * .55); replaySVG.strokeColor = "red"; replaySVG.strokeWidth = menuStrokeWidth; replaySVG.strokeCap = "round"; replaySVG.firstSegment.point -= [menuStrokeWidth, menuStrokeWidth2]; replaySVG.lastSegment.remove(); replaySVG.lastSegment.point += [menuStrokeWidth2, menuStrokeWidth2]; var shareButton = new Path.Rectangle(new Point(viewWidth2 + menuButtonBiasX - menuButtonWidth2, viewHeight2 + menuButtonWidth2 - menuButtonHeight + menuButtonBiasY), menuButtonSize); shareButton.fillColor = "white"; var shareSVG = new Path.Rectangle(new Point(viewWidth2 + menuButtonBiasX - menuButtonWidth2, viewHeight2 + menuButtonWidth2 - menuButtonHeight + menuButtonBiasY), menuButtonSize); shareSVG.strokeColor = "blue"; shareSVG.strokeWidth = menuStrokeWidth; var shareSVG1 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY)); var shareSVG2 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX - menuButtonHeight2, viewHeight2 - menuButtonHeight2 + menuButtonBiasY)); var shareSVG3 = new Path.Line(new Point(viewWidth2 + menuButtonBiasX, viewHeight2 - menuButtonHeight + menuButtonBiasY), new Point(viewWidth2 + menuButtonBiasX + menuButtonHeight2, viewHeight2 - menuButtonHeight2 + menuButtonBiasY)); shareSVG1.strokeColor = "blue"; shareSVG1.strokeWidth = menuStrokeWidth; shareSVG2.strokeColor = "blue"; shareSVG2.strokeWidth = menuStrokeWidth; shareSVG2.strokeCap = "round"; shareSVG3.strokeColor = "blue"; shareSVG3.strokeWidth = menuStrokeWidth; shareSVG3.strokeCap = "round"; var rankText = new PointText({ point: [viewWidth2, viewHeight2 + rankBiasY - 2.5 * rankTextFontSize], justification: "center", fillColor: "black", fontSize: rankTextFontSize }); rankText.content = ""; var menuGroup = new Group(menuBox, replayButton, replaySVG, shareButton, shareSVG, shareSVG1, shareSVG2, shareSVG3, rankText); menuGroup.visible = false; replayButton.onMouseDown = function(event) { event.preventDefault(); init() }; shareButton.onMouseDown = function(event) { event.preventDefault(); dp_share(); }; var tutorialBox = new Shape.Rectangle({ point: [viewWidth2 - tutorialWidth2, viewHeight2 - tutorialHeight2 + tutorialBiasY], size: tutorialSize, strokeColor: "black", fillColor: "white", strokeJoin: "round", strokeWidth: tutorialStrokeWidth }); var tutorialText = new PointText({ point: [viewWidth2, viewHeight2 + tutorialBiasY+5], justification: "center", fillColor: "black", fontSize: tutorialTextFontSize }); tutorialText.content = "更多游戏"; var tutorialGroup = new Group(tutorialBox, tutorialText); tutorialGroup.visible = true; tutorialBox.onMouseDown = function(event) { clickMore(); }; tutorialText.onMouseDown = function(event) { clickMore(); }; 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)); arrowSVG.strokeColor = "blue"; arrowSVG.strokeWidth = menuStrokeWidth; var arrowText = new PointText({ point: [viewWidth - arrowWidth - arrowBiasX, arrowHeight + arrowTextFontSize], justification: "center", fillColor: "black", fontSize: arrowTextFontSize }); arrowText.content = "分享到朋友圈"; var arrowGroup = new Group(arrowSVG, arrowText); arrowGroup.visible = false; slideDown = false; slideBack.onMouseDown = function(event) { event.preventDefault(); slideDown = true; mouseX = event.point.x; slideX = event.point.x - viewWidth2 }; slideBack.onMouseMove = function(event) { mouseX = event.point.x; slideX = event.point.x - viewWidth2 }; slideBack.onMouseUp = function(event) { slideDown = false }; slideBack.onMouseLeave = function(event) { slideDown = false }; function init() { timer = 0; percentage = "0%"; slideX = 0; alpha = 0; omega = 0; angle = 0; status = 1; randomBias = (Math.random() - .5) * maxRandomBias; if (randomBias < 0) { randomBias -= minRandomBias } else { randomBias += minRandomBias } biasX = randomBias; menuGroup.visible = false; tutorialGroup.visible = false; arrowGroup.visible = false; versionText.visible = true; hintLine.visible = true; hintLine.dashArray = []; HideContent("desktop-ad"); document.title = "强迫症矫正棍——你以为你能调平?" } function uuid(len, radix) { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), uuid = [], i; radix = radix || chars.length; if (len) { for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix] } else { var r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-"; uuid[14] = "4"; for (i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random() * 16; uuid[i] = chars[i == 19 ? r & 3 | 8 : r] } } } return uuid.join("") } function encourage(timer) { if (timer < 10) { return "\n“我一定能把它调平!”" } else if (timer < 30) { return "\n“有一种把它调平的感觉在心中发芽。”" } else if (timer < 60) { return "\n“呼,好像刚刚自学完成刚体力学!”" } else if (timer < 120) { return "\n“这成绩要是分享一下的话... :D”" } else { return "\n“我已经知道了,这个世界不是完美的”" } } function fillRankText(percentage) { if (!isiphone && !shared) { rankText.content = "别自己刷啦,分享到朋友圈\n看下好友的强迫症如何?\n" } else { rankText.content = rankTextFirstLine } if (!percentage) { var timerInt = parseInt(timer); percentage = (positionList[timerInt + 1] - positionList[timerInt]) * (timer - timerInt) + positionList[timerInt]; percentage = (percentage * 100).toFixed(2) + "%" } rankText.content += "\n强迫症矫正棍上坚持了" + timer.toFixed(2) + "秒"; rankText.content += encourage(timer); dp_submitScore(timer.toFixed(2)); } function onFrame(event) { if (status === 0) { if (!helpText.visible) { helpText.visible = true } if (loading) { loading = false; HideContent("inputpage") } } else if (status === 1) { if (event.delta > 5) { event.delta = 5 } if (slideDown) { slideBack.opacity = 1; slideCircle.position.x = mouseX } else { slideBack.opacity = 0 } timerText.content = timer.toFixed(2); timerText.content += "''"; if (timer > 20 && !hintLine.dashArray.length) { hintLine.dashArray = [1, 4] } if (timer > 30 && hintLine.visible && !shared) { hintLine.visible = false } angleArc = angle / 180 * Math.PI; cos = Math.cos(angleArc); sin = Math.sin(angleArc); tan = Math.tan(angleArc); realBiasX = biasX * cos + sin * barHeight2 + sin * characterHeight2; realBiasY = characterHeight2 * cos - biasX * sin + barHeight2 * cos; character.position = new Point(viewWidth2 + realBiasX, viewHeight2 - realBiasY); if (slideDown) { newBiasX = biasX + slideX * event.delta * slideFactor; if (newBiasX < barWidth2 && newBiasX > -barWidth2) { biasX = newBiasX } } timer += event.delta; alpha += event.delta * realBiasX * alphaFactor; omega += event.delta * alpha; if (omega < minOmega && omega > 0 && alpha < 0) { omega = minOmega } else if (omega > -minOmega && omega < 0 && alpha > 0) { omega = -minOmega } deltaAngle = event.delta * omega; angle += deltaAngle; rect.rotation = angle; character.rotation = angle; if (angle < -90 || angle > 90) { times_played = parseInt(getCookie("times_played")); if (!times_played) { times_played = 0 } setCookie("times_played", times_played + 1); status = 2; slideBack.opacity = 0; if (positionList.length) { fillRankText(); } else { fillRankText(); } tutorialGroup.visible = true; } } else if (status == 2) { if (!menuGroup.visible) { timerText.content = timer.toFixed(2); timerText.content += "''"; if (times_played >= 1 && !(times_played % 5)) { //ShowContent("desktop-ad") } menuGroup.opacity = 0; menuGroup.visible = true; versionText.opacity = 0; versionText.visible = true; if (!shared) { arrowGroup.opacity = 0; arrowGroup.visible = true } if (times_played < 20) { tutorialGroup.opacity = 0; tutorialGroup.visible = true } } if (menuGroup.opacity < 1) { opacity = menuGroup.opacity += 5 * event.delta; if (opacity > 1) { opacity = 1 } menuGroup.opacity = opacity; versionText.opacity = opacity; if (!shared) { arrowGroup.opacity = opacity } if (times_played < 20) { tutorialGroup.opacity = opacity } } tutorialGroup.visible = true; } } function HideContent(d) { $('#' + d).hide(); } function ShowContent(d) { $('#' + d).show(1000); }