Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/hextris/js/render.js
1036 views
1
function render() {
2
var grey = '#bdc3c7';
3
if (gameState === 0) {
4
grey = "rgb(220, 223, 225)";
5
}
6
7
ctx.clearRect(0, 0, trueCanvas.width, trueCanvas.height);
8
clearGameBoard();
9
if (gameState === 1 || gameState === 2 || gameState === -1 || gameState === 0) {
10
if (op < 1) {
11
op += 0.01;
12
}
13
ctx.globalAlpha = op;
14
drawPolygon(trueCanvas.width / 2 , trueCanvas.height / 2 , 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, grey, false,6);
15
drawTimer();
16
ctx.globalAlpha = 1;
17
}
18
19
var i;
20
for (i = 0; i < MainHex.blocks.length; i++) {
21
for (var j = 0; j < MainHex.blocks[i].length; j++) {
22
var block = MainHex.blocks[i][j];
23
block.draw(true, j);
24
}
25
}
26
for (i = 0; i < blocks.length; i++) {
27
blocks[i].draw();
28
}
29
30
MainHex.draw();
31
if (gameState ==1 || gameState ==-1 || gameState === 0) {
32
drawScoreboard();
33
}
34
35
for (i = 0; i < MainHex.texts.length; i++) {
36
var alive = MainHex.texts[i].draw();
37
if(!alive){
38
MainHex.texts.splice(i,1);
39
i--;
40
}
41
}
42
43
if ((MainHex.ct < 650 && (gameState !== 0) && !MainHex.playThrough)) {
44
if (MainHex.ct > (650 - 50)) {
45
ctx.globalAlpha = (50 - (MainHex.ct - (650 - 50)))/50;
46
}
47
48
if (MainHex.ct < 50) {
49
ctx.globalAlpha = (MainHex.ct)/50;
50
}
51
52
renderBeginningText();
53
ctx.globalAlpha = 1;
54
}
55
56
if (gameState == -1) {
57
ctx.globalAlpha = 0.9;
58
ctx.fillStyle = 'rgb(236,240,241)';
59
ctx.fillRect(0, 0, trueCanvas.width, trueCanvas.height);
60
ctx.globalAlpha = 1;
61
}
62
63
settings.prevScale = settings.scale;
64
settings.hexWidth = settings.baseHexWidth * settings.scale;
65
settings.blockHeight = settings.baseBlockHeight * settings.scale;
66
}
67
68
function renderBeginningText() {
69
var upperheight = (trueCanvas.height/2) - ((settings.rows * settings.blockHeight) * (2/Math.sqrt(3))) * (5/6);
70
var lowerheight = (trueCanvas.height/2) + ((settings.rows * settings.blockHeight) * (2/Math.sqrt(3))) * (11/16);
71
var text = '';
72
var mob, fontSize;
73
if(/mobile|Mobile|iOS|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
74
mob = true;
75
input_text = 'Tap the screen\'s left and right'
76
action_text = 'sides to rotate the hexagon'
77
score_text = 'Match 3+ blocks to score'
78
fontSize = 35
79
} else {
80
mob = false
81
input_text = 'Use the right and left arrow keys'
82
action_text = 'to rotate the hexagon'
83
score_text = 'Match 3+ blocks to score!'
84
fontSize = 27
85
}
86
renderText((trueCanvas.width)/2 + 2 * settings.scale,upperheight-0*settings.scale, fontSize, '#2c3e50', input_text);
87
renderText((trueCanvas.width)/2 + 2 * settings.scale,upperheight+33*settings.scale, fontSize, '#2c3e50', action_text);
88
if (!mob) {
89
drawKey("",(trueCanvas.width)/2 + 2 * settings.scale-2.5,upperheight+38*settings.scale);
90
}
91
92
renderText((trueCanvas.width)/2 + 2 * settings.scale,lowerheight,fontSize, '#2c3e50', score_text);
93
}
94
95
function drawKey(key, x, y) {
96
ctx.save();
97
switch (key) {
98
case "left":
99
ctx.translate(x, y + settings.scale * 13);
100
ctx.rotate(3.14159);
101
ctx.font = "20px Fontawesome";
102
ctx.scale(settings.scale, settings.scale);
103
ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
104
break;
105
case "right":
106
ctx.font = "20px Fontawesome";
107
ctx.translate(x , y + settings.scale * 27.5);
108
ctx.scale(settings.scale, settings.scale);
109
ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
110
break;
111
112
default:
113
drawKey("left", x - 5, y);
114
drawKey("right", x + 5, y);
115
}
116
ctx.restore();
117
}
118
119