Path: blob/main/public/games/files/hextris/js/view.js
1036 views
// t: current time, b: begInnIng value, c: change In value, d: duration1function easeOutCubic(t, b, c, d) {2return c * ((t = t / d - 1) * t * t + 1) + b;3}45function renderText(x, y, fontSize, color, text, font) {6ctx.save();7if (!font) {8var font = '20px Exo';9}1011fontSize *= settings.scale;12ctx.font = fontSize + font;13ctx.textAlign = 'center';14ctx.fillStyle = color;15ctx.fillText(text, x, y + (fontSize / 2) - 9 * settings.scale);16ctx.restore();17}1819function drawScoreboard() {20if (scoreOpacity < 1) {21scoreOpacity += 0.01;22textOpacity += 0.01;23}24ctx.globalAlpha = textOpacity;25var scoreSize = 50;26var scoreString = String(score);27if (scoreString.length == 6) {28scoreSize = 43;29} else if (scoreString.length == 7) {30scoreSize = 35;31} else if (scoreString.length == 8) {32scoreSize = 31;33} else if (scoreString.length == 9) {34scoreSize = 27;35}36//if (rush ==1){37var color = "rgb(236, 240, 241)";38//}39var fontSize = settings.platform == 'mobile' ? 35 : 30;40var h = trueCanvas.height / 2 + gdy + 100 * settings.scale;41if (gameState === 0) {42renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome');43renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2.1 + gdy - 155 * settings.scale, 150, "#2c3e50", "Hextris");44renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, h + 10, fontSize, "rgb(44,62,80)", 'Play!');45} else if (gameState != 0 && textOpacity > 0) {46textOpacity -= 0.05;47renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome');48renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 155 * settings.scale, 150, "#2c3e50", "Hextris");49renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, h, fontSize, "rgb(44,62,80)", 'Play!');50ctx.globalAlpha = scoreOpacity;51renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, color, score);52} else {53ctx.globalAlpha = scoreOpacity;54renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, color, score);55}5657ctx.globalAlpha = 1;58}5960function clearGameBoard() {61drawPolygon(trueCanvas.width / 2, trueCanvas.height / 2, 6, trueCanvas.width / 2, 30, hexagonBackgroundColor, 0, 'rgba(0,0,0,0)');62}6364function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor) {65ctx.fillStyle = fillColor;66ctx.lineWidth = lineWidth;67ctx.strokeStyle = lineColor;6869ctx.beginPath();70var coords = rotatePoint(0, radius, theta);71ctx.moveTo(coords.x + x, coords.y + y);72var oldX = coords.x;73var oldY = coords.y;74for (var i = 0; i < sides; i++) {75coords = rotatePoint(oldX, oldY, 360 / sides);76ctx.lineTo(coords.x + x, coords.y + y);77oldX = coords.x;78oldY = coords.y;79}8081ctx.closePath();82ctx.fill();83ctx.stroke();84ctx.strokeStyle = 'rgba(0,0,0,0)';85}8687function toggleClass(element, active) {88if ($(element).hasClass(active)) {89$(element).removeClass(active);90} else {91$(element).addClass(active);92}93}9495function showText(text) {96var messages = {97'paused': "<div class='centeredHeader unselectable'>Game Paused</div>",98'pausedAndroid': "<div class='centeredHeader unselectable'>Game Paused</div><div class='unselectable centeredSubHeader' style='position:absolute;margin-left:-150px;left:50%;margin-top:20px;width:300px;font-size:16px;'><a href = 'https://play.google.com/store/apps/details?id=com.hextris.hextrisadfree' target='_blank'Want to support the developers? Don't like ads? Tap for Hextris ad-free!</a></div>",99'pausediOS': "<div class='centeredHeader unselectable'>Game Paused</div><div class='unselectable centeredSubHeader' style='position:absolute;margin-left:-150px;left:50%;margin-top:20px;width:300px;font-size:16px;'><a href = 'https://itunes.apple.com/us/app/hextris-ad-free/id912895524?mt=8' target='_blank'>Want to support the developers? Don't like ads? Tap for Hextris ad-free!</a></div>",100'pausedOther': "<div class='centeredHeader unselectable'>Game Paused</div><div class='unselectable centeredSubHeader' style='margin-top:10px;position:absolute;left:50%;margin-left:-190px;max-width:380px;font-size:18px;'><a href = 'http://hextris.github.io/' target='_blank'>Want to support the developers? Click here to buy one of the ad-free mobile versions!</a></div>",101'start': "<div class='centeredHeader unselectable' style='line-height:80px;'>Press enter to start</div>"102};103104if (text == 'paused') {105if (settings.os == 'android') {106text = 'pausedAndroid'107} else if (settings.os == 'ios') {108text = 'pausediOS'109} else if (settings.platform == 'nonmobile') {110text = 'pausedOther'111}112}113114if (text == 'gameover') {115//Clay('client.share.any', {text: 'Think you can beat my score of '+ score + ' in Super Cool Game?'})116$("#gameoverscreen").fadeIn();117}118$(".overlay").html(messages[text]);119$(".overlay").fadeIn("1000", "swing");120121}122123function setMainMenu() {124gameState = 4;125canRestart = false;126setTimeout(function() {127canRestart = 's';128}, 500);129$('#restartBtn').hide();130if ($("#pauseBtn").replace(/^.*[\\\/]/, '') == "btn_pause.svg") {131$("#pauseBtn").attr("src","./images/btn_resume.svg");132} else {133$("#pauseBtn").attr("src","./images/btn_pause.svg");134}135}136137function hideText() {138$(".overlay").fadeOut(150, function() {139$(".overlay").html("");140})141}142143function gameOverDisplay() {144settings.ending_block=false;145Cookies.set("visited",true);146var c = document.getElementById("canvas");147c.className = "blur";148updateHighScores();149if (highscores.length === 0 ){150$("#currentHighScore").text(0);151}152else {153$("#currentHighScore").text(highscores[0])154}155$("#gameoverscreen").fadeIn();156$("#buttonCont").fadeIn();157$("#container").fadeIn();158$("#socialShare").fadeIn();159$("#restart").fadeIn();160set_score_pos();161}162163function updateHighScores (){164$("#cScore").text(score);165$("#1place").text(highscores[0]);166$("#2place").text(highscores[1]);167$("#3place").text(highscores[2]);168}169170var pausable = true;171function pause(o) {172if (gameState == 0 || gameState == 2 || !pausable) {173return;174}175176pausable = false;177writeHighScores();178var message;179if (o) {180message = '';181} else {182message = 'paused';183}184185var c = document.getElementById("canvas");186if (gameState == -1) {187$('#fork-ribbon').fadeOut(300, 'linear');188$('#restartBtn').fadeOut(300, "linear");189$('#buttonCont').fadeOut(300, "linear");190if ($('#helpScreen').is(':visible')) {191$('#helpScreen').fadeOut(300, "linear");192}193194$("#pauseBtn").attr("src", "./images/btn_pause.svg");195$('.helpText').fadeOut(300, 'linear');196$('#overlay').fadeOut(300, 'linear');197hideText();198setTimeout(function() {199gameState = prevGameState;200pausable =true;201}, 400);202} else if (gameState != -2 && gameState !== 0 && gameState !== 2) {203$('#restartBtn').fadeIn(300, "linear");204$('#buttonCont').fadeIn(300, "linear");205$('.helpText').fadeIn(300, 'linear');206if (message == 'paused') {207showText(message);208}209$('#fork-ribbon').fadeIn(300, 'linear');210$("#pauseBtn").attr("src","./images/btn_resume.svg");211$('#overlay').fadeIn(300, 'linear');212prevGameState = gameState;213setTimeout(function() {214pausable = true;215}, 400);216gameState = -1;217}218}219220221