Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/hextris/js/view.js
1036 views
1
// t: current time, b: begInnIng value, c: change In value, d: duration
2
function easeOutCubic(t, b, c, d) {
3
return c * ((t = t / d - 1) * t * t + 1) + b;
4
}
5
6
function renderText(x, y, fontSize, color, text, font) {
7
ctx.save();
8
if (!font) {
9
var font = '20px Exo';
10
}
11
12
fontSize *= settings.scale;
13
ctx.font = fontSize + font;
14
ctx.textAlign = 'center';
15
ctx.fillStyle = color;
16
ctx.fillText(text, x, y + (fontSize / 2) - 9 * settings.scale);
17
ctx.restore();
18
}
19
20
function drawScoreboard() {
21
if (scoreOpacity < 1) {
22
scoreOpacity += 0.01;
23
textOpacity += 0.01;
24
}
25
ctx.globalAlpha = textOpacity;
26
var scoreSize = 50;
27
var scoreString = String(score);
28
if (scoreString.length == 6) {
29
scoreSize = 43;
30
} else if (scoreString.length == 7) {
31
scoreSize = 35;
32
} else if (scoreString.length == 8) {
33
scoreSize = 31;
34
} else if (scoreString.length == 9) {
35
scoreSize = 27;
36
}
37
//if (rush ==1){
38
var color = "rgb(236, 240, 241)";
39
//}
40
var fontSize = settings.platform == 'mobile' ? 35 : 30;
41
var h = trueCanvas.height / 2 + gdy + 100 * settings.scale;
42
if (gameState === 0) {
43
renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome');
44
renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2.1 + gdy - 155 * settings.scale, 150, "#2c3e50", "Hextris");
45
renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, h + 10, fontSize, "rgb(44,62,80)", 'Play!');
46
} else if (gameState != 0 && textOpacity > 0) {
47
textOpacity -= 0.05;
48
renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome');
49
renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 155 * settings.scale, 150, "#2c3e50", "Hextris");
50
renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, h, fontSize, "rgb(44,62,80)", 'Play!');
51
ctx.globalAlpha = scoreOpacity;
52
renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, color, score);
53
} else {
54
ctx.globalAlpha = scoreOpacity;
55
renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, scoreSize, color, score);
56
}
57
58
ctx.globalAlpha = 1;
59
}
60
61
function clearGameBoard() {
62
drawPolygon(trueCanvas.width / 2, trueCanvas.height / 2, 6, trueCanvas.width / 2, 30, hexagonBackgroundColor, 0, 'rgba(0,0,0,0)');
63
}
64
65
function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor) {
66
ctx.fillStyle = fillColor;
67
ctx.lineWidth = lineWidth;
68
ctx.strokeStyle = lineColor;
69
70
ctx.beginPath();
71
var coords = rotatePoint(0, radius, theta);
72
ctx.moveTo(coords.x + x, coords.y + y);
73
var oldX = coords.x;
74
var oldY = coords.y;
75
for (var i = 0; i < sides; i++) {
76
coords = rotatePoint(oldX, oldY, 360 / sides);
77
ctx.lineTo(coords.x + x, coords.y + y);
78
oldX = coords.x;
79
oldY = coords.y;
80
}
81
82
ctx.closePath();
83
ctx.fill();
84
ctx.stroke();
85
ctx.strokeStyle = 'rgba(0,0,0,0)';
86
}
87
88
function toggleClass(element, active) {
89
if ($(element).hasClass(active)) {
90
$(element).removeClass(active);
91
} else {
92
$(element).addClass(active);
93
}
94
}
95
96
function showText(text) {
97
var messages = {
98
'paused': "<div class='centeredHeader unselectable'>Game Paused</div>",
99
'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>",
100
'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>",
101
'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>",
102
'start': "<div class='centeredHeader unselectable' style='line-height:80px;'>Press enter to start</div>"
103
};
104
105
if (text == 'paused') {
106
if (settings.os == 'android') {
107
text = 'pausedAndroid'
108
} else if (settings.os == 'ios') {
109
text = 'pausediOS'
110
} else if (settings.platform == 'nonmobile') {
111
text = 'pausedOther'
112
}
113
}
114
115
if (text == 'gameover') {
116
//Clay('client.share.any', {text: 'Think you can beat my score of '+ score + ' in Super Cool Game?'})
117
$("#gameoverscreen").fadeIn();
118
}
119
$(".overlay").html(messages[text]);
120
$(".overlay").fadeIn("1000", "swing");
121
122
}
123
124
function setMainMenu() {
125
gameState = 4;
126
canRestart = false;
127
setTimeout(function() {
128
canRestart = 's';
129
}, 500);
130
$('#restartBtn').hide();
131
if ($("#pauseBtn").replace(/^.*[\\\/]/, '') == "btn_pause.svg") {
132
$("#pauseBtn").attr("src","./images/btn_resume.svg");
133
} else {
134
$("#pauseBtn").attr("src","./images/btn_pause.svg");
135
}
136
}
137
138
function hideText() {
139
$(".overlay").fadeOut(150, function() {
140
$(".overlay").html("");
141
})
142
}
143
144
function gameOverDisplay() {
145
settings.ending_block=false;
146
Cookies.set("visited",true);
147
var c = document.getElementById("canvas");
148
c.className = "blur";
149
updateHighScores();
150
if (highscores.length === 0 ){
151
$("#currentHighScore").text(0);
152
}
153
else {
154
$("#currentHighScore").text(highscores[0])
155
}
156
$("#gameoverscreen").fadeIn();
157
$("#buttonCont").fadeIn();
158
$("#container").fadeIn();
159
$("#socialShare").fadeIn();
160
$("#restart").fadeIn();
161
set_score_pos();
162
}
163
164
function updateHighScores (){
165
$("#cScore").text(score);
166
$("#1place").text(highscores[0]);
167
$("#2place").text(highscores[1]);
168
$("#3place").text(highscores[2]);
169
}
170
171
var pausable = true;
172
function pause(o) {
173
if (gameState == 0 || gameState == 2 || !pausable) {
174
return;
175
}
176
177
pausable = false;
178
writeHighScores();
179
var message;
180
if (o) {
181
message = '';
182
} else {
183
message = 'paused';
184
}
185
186
var c = document.getElementById("canvas");
187
if (gameState == -1) {
188
$('#fork-ribbon').fadeOut(300, 'linear');
189
$('#restartBtn').fadeOut(300, "linear");
190
$('#buttonCont').fadeOut(300, "linear");
191
if ($('#helpScreen').is(':visible')) {
192
$('#helpScreen').fadeOut(300, "linear");
193
}
194
195
$("#pauseBtn").attr("src", "./images/btn_pause.svg");
196
$('.helpText').fadeOut(300, 'linear');
197
$('#overlay').fadeOut(300, 'linear');
198
hideText();
199
setTimeout(function() {
200
gameState = prevGameState;
201
pausable =true;
202
}, 400);
203
} else if (gameState != -2 && gameState !== 0 && gameState !== 2) {
204
$('#restartBtn').fadeIn(300, "linear");
205
$('#buttonCont').fadeIn(300, "linear");
206
$('.helpText').fadeIn(300, 'linear');
207
if (message == 'paused') {
208
showText(message);
209
}
210
$('#fork-ribbon').fadeIn(300, 'linear');
211
$("#pauseBtn").attr("src","./images/btn_resume.svg");
212
$('#overlay').fadeIn(300, 'linear');
213
prevGameState = gameState;
214
setTimeout(function() {
215
pausable = true;
216
}, 400);
217
gameState = -1;
218
}
219
}
220
221