2014-08-23 02:10:55 +00:00
|
|
|
function render() {
|
|
|
|
var grey = '#bdc3c7';
|
|
|
|
if (gameState === 0) {
|
|
|
|
grey = "rgb(220, 223, 225)";
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.clearRect(0, 0, trueCanvas.width, trueCanvas.height);
|
|
|
|
clearGameBoard();
|
|
|
|
if (gameState === 1 || gameState === 2 || gameState === -1 || gameState === 0) {
|
|
|
|
if (op < 1) {
|
|
|
|
op += 0.01;
|
|
|
|
}
|
|
|
|
ctx.globalAlpha = op;
|
|
|
|
drawPolygon(trueCanvas.width / 2 , trueCanvas.height / 2 , 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, grey, false,6);
|
|
|
|
drawTimer();
|
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var i;
|
|
|
|
for (i = 0; i < MainHex.blocks.length; i++) {
|
|
|
|
for (var j = 0; j < MainHex.blocks[i].length; j++) {
|
|
|
|
var block = MainHex.blocks[i][j];
|
|
|
|
block.draw(true, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < blocks.length; i++) {
|
|
|
|
blocks[i].draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainHex.draw();
|
2015-03-14 20:37:12 +00:00
|
|
|
if (gameState ==1 || gameState ==-1 || gameState === 0) {
|
|
|
|
drawScoreboard();
|
|
|
|
}
|
|
|
|
|
2014-08-23 02:10:55 +00:00
|
|
|
for (i = 0; i < MainHex.texts.length; i++) {
|
|
|
|
var alive = MainHex.texts[i].draw();
|
|
|
|
if(!alive){
|
|
|
|
MainHex.texts.splice(i,1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 03:09:21 +00:00
|
|
|
if ((MainHex.ct < 650 && (gameState !== 0) && !MainHex.playThrough)) {
|
|
|
|
if (MainHex.ct > (650 - 50)) {
|
|
|
|
ctx.globalAlpha = (50 - (MainHex.ct - (650 - 50)))/50;
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (MainHex.ct < 50) {
|
|
|
|
ctx.globalAlpha = (MainHex.ct)/50;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBeginningText();
|
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameState == -1) {
|
|
|
|
ctx.globalAlpha = 0.9;
|
|
|
|
ctx.fillStyle = 'rgb(236,240,241)';
|
|
|
|
ctx.fillRect(0, 0, trueCanvas.width, trueCanvas.height);
|
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.prevScale = settings.scale;
|
|
|
|
settings.hexWidth = settings.baseHexWidth * settings.scale;
|
|
|
|
settings.blockHeight = settings.baseBlockHeight * settings.scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderBeginningText() {
|
2015-09-25 22:44:13 +00:00
|
|
|
var upperheight = (trueCanvas.height/2) - ((settings.rows * settings.blockHeight) * (2/Math.sqrt(3))) * (5/6);
|
|
|
|
var lowerheight = (trueCanvas.height/2) + ((settings.rows * settings.blockHeight) * (2/Math.sqrt(3))) * (11/16);
|
2015-09-21 06:27:05 +00:00
|
|
|
var text = '';
|
2015-09-25 22:44:13 +00:00
|
|
|
var mob, fontSize;
|
2015-09-25 23:13:44 +00:00
|
|
|
if(/mobile|Mobile|iOS|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
2015-09-21 06:27:05 +00:00
|
|
|
mob = true;
|
2015-09-25 22:44:13 +00:00
|
|
|
input_text = 'Tap the screen\'s left and ride'
|
|
|
|
action_text = 'sides to rotate the hexagon'
|
|
|
|
score_text = 'Match 3+ blocks to score'
|
|
|
|
fontSize = 35
|
2015-09-21 06:27:05 +00:00
|
|
|
} else {
|
2015-09-25 23:13:44 +00:00
|
|
|
mob = false
|
2015-09-21 06:27:05 +00:00
|
|
|
input_text = 'Use the right and left arrow keys'
|
|
|
|
action_text = 'to rotate the hexagon'
|
|
|
|
score_text = 'Match 3+ blocks to score!'
|
2015-09-25 23:13:44 +00:00
|
|
|
fontSize = 27
|
2015-09-21 06:27:05 +00:00
|
|
|
}
|
2015-09-25 23:13:44 +00:00
|
|
|
renderText((trueCanvas.width)/2 + 2 * settings.scale,upperheight-0*settings.scale, fontSize, '#2c3e50', input_text);
|
|
|
|
renderText((trueCanvas.width)/2 + 2 * settings.scale,upperheight+33*settings.scale, fontSize, '#2c3e50', action_text);
|
2015-09-21 06:27:05 +00:00
|
|
|
if (!mob) {
|
2015-09-25 23:13:44 +00:00
|
|
|
drawKey("",(trueCanvas.width)/2 + 2 * settings.scale-2.5,upperheight+38*settings.scale);
|
2015-09-21 06:27:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 22:44:13 +00:00
|
|
|
renderText((trueCanvas.width)/2 + 2 * settings.scale,lowerheight,fontSize, '#2c3e50', score_text);
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawKey(key, x, y) {
|
|
|
|
ctx.save();
|
|
|
|
switch (key) {
|
|
|
|
case "left":
|
2015-03-14 19:47:52 +00:00
|
|
|
ctx.translate(x, y + settings.scale * 13);
|
2014-08-23 02:10:55 +00:00
|
|
|
ctx.rotate(3.14159);
|
|
|
|
ctx.font = "20px Fontawesome";
|
|
|
|
ctx.scale(settings.scale, settings.scale);
|
|
|
|
ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
ctx.font = "20px Fontawesome";
|
2015-03-14 19:47:52 +00:00
|
|
|
ctx.translate(x , y + settings.scale * 27.5);
|
2014-08-23 02:10:55 +00:00
|
|
|
ctx.scale(settings.scale, settings.scale);
|
|
|
|
ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-03-14 19:47:52 +00:00
|
|
|
drawKey("left", x - 5, y);
|
|
|
|
drawKey("right", x + 5, y);
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
}
|