Merge branch 'gh-pages' of https://github.com/teamsnowman/hextris into gh-pages

This commit is contained in:
Noah Moroze 2014-05-26 12:30:45 -04:00
commit 95e7c1b0db
7 changed files with 83 additions and 11 deletions

View file

@ -63,6 +63,7 @@
<script type = 'text/javascript' src="js/entities.js"></script>
<script type = 'text/javascript' src="js/Block.js"></script>
<script type = 'text/javascript' src="js/Clock.js"></script>
<script type = 'text/javascript' src="js/Text.js"></script>
<script type = 'text/javascript' src="js/input.js"></script>
<script type = 'text/javascript' src="js/checking.js"></script>
<script type = 'text/javascript' src='js/update.js'></script>

View file

@ -12,8 +12,9 @@ function Clock(sideLength) {
this.strokeColor = 'blue';
this.x = trueCanvas.width / 2;
this.y = trueCanvas.height / 2;
this.lastCombo;
this.lastCombo = Date.now() - 5000;
this.comboMultiplier = 1;
this.texts = [];
for (var i = 0; i < this.sides; i++) {
this.blocks.push([]);
@ -150,5 +151,25 @@ function Clock(sideLength) {
this.angle += this.angularVelocity;
}
drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle, this.fillColor, 0, 'rgba(0,0,0,0)');
this.drawClockHand();
};
this.drawClockHand = function() {
ctx.beginPath();
var handColor = '#7f8c8d';
ctx.lineWidth = 3;
ctx.strokeStyle = handColor;
ctx.moveTo(this.x, this.y);
if(Date.now()-this.lastCombo >5000){
var handAngle =0;
}
else {
var handAngle = (360 * (Date.now() - this.lastCombo) / 5000);
}
var coords = rotatePoint(0, this.sideLength / 2 * Math.sqrt(3), (handAngle+180)%360);
ctx.lineTo(this.x + coords.x, this.y + coords.y);
ctx.stroke();
ctx.strokeStyle = 'rgba(0,0,0,0)';
}
}

32
js/Text.js Normal file
View file

@ -0,0 +1,32 @@
function Text(x,y,text,font,color,incrementFunction){
this.x = x;
this.y = y;
this.font = font;
this.color = color;
this.opacity =1;
this.text = text;
this.draw = function(){
if(this.opacity>0){
ctx.font= this.font;
ctx.fillStyle = this.color;
ctx.globalAlpha = this.opacity;
ctx.fillText(text,this.x,this.y);
ctx.globalAlpha =1;
//this.opacity = 1-(Date.now()-MainClock.lastCombo)/5000;
incrementFunction(this);
return true;
}
else{
return false;
}
}
}
function fadeUpAndOut(text){
text.opacity -=0.05;
text.y-=3;
}

View file

@ -62,6 +62,7 @@ function consolidateBlocks(clock,side,index){
clock.blocks[arr[0]][arr[1]].deleted = 1;
}
}
var lastBlock = clock.blocks[arr[0]][arr[1]]
// add scores
var now = Date.now();
if(now - clock.lastCombo < 5000 ){
@ -72,6 +73,8 @@ function consolidateBlocks(clock,side,index){
clock.lastCombo = now;
clock.comboMultiplier = 1;
}
score += deleting.length * deleting.length * clock.comboMultiplier;
var adder = deleting.length * deleting.length * clock.comboMultiplier;
clock.texts.push(new Text(clock.x,clock.y,"+ "+adder.toString(),"bold Roboto 24px","#9b59b6",fadeUpAndOut));
score += adder;
}

View file

@ -314,7 +314,7 @@ window.onblur = function (e) {
if (gameState == -1) {
gameState = prevGameState;
}
else if(gameState != -2 && gameState != 0) {
else if(gameState == 1) {
prevGameState = gameState;
gameState = -1;
}

View file

@ -1,7 +1,9 @@
var grey = '#bdc3c7';
function render() {
ctx.clearRect(0, 0, trueCanvas.width, trueCanvas.height);
clearGameBoard();
if (gameState == -2) {
if (Date.now() - startTime > 1300) {
var op = (Date.now() - startTime - 1300)/500;
@ -9,13 +11,14 @@ function render() {
op = 1;
}
ctx.globalAlpha = op;
drawPolygon(trueCanvas.width / 2 , trueCanvas.height / 2 , 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, "#bdc3c7", false,6);
drawPolygon(trueCanvas.width / 2 , trueCanvas.height / 2 , 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, grey, false,6);
ctx.globalAlpha = 1;
}
} else {
drawPolygon(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, '#bdc3c7', false, 6);
drawPolygon(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, 6, (settings.rows * settings.blockHeight) * (2/Math.sqrt(3)) + settings.hexWidth, 30, grey, false, 6);
}
for (var i in MainClock.blocks) {
for (var j = 0; j < MainClock.blocks[i].length; j++) {
var block = MainClock.blocks[i][j];
@ -27,9 +30,19 @@ function render() {
blocks[i].draw();
}
MainClock.draw();
if (gameState == 1) {
drawScoreboard();
}
for (var i in MainClock.texts) {
var alive = MainClock.texts[i].draw();
if(!alive){
MainClock.texts.splice(i,1)
}
i--;
}
settings.prevScale = settings.scale;
}

View file

@ -18,16 +18,17 @@ function showModal(text, secondaryText) {
ctx.fillText(secondaryText, trueCanvas.width / 2, trueCanvas.height / 2 + fontSizeLarge / 4 + fontSizeSmall / 4 + 30);
}
function renderText(x, y, fontSize, text) {
function renderText(x, y, fontSize, color, text) {
// if(typeof text == 'string' || text instanceof String) {
// text = [text];
// }
// fontSize = fontSize || 50;
ctx.font = fontSize + 'px Roboto'; // figure out what is not working
// var lineHeight =;
ctx.font = fontSize + 'px/0 Roboto'; // figure out what is not working
ctx.textAlign = 'center';
ctx.fillStyle = 'rgb(236, 240, 241)';
// ctx.fillStyle = 'rgb(236, 240, 241)';
ctx.fillStyle = color;
// for(var i=0; i<text.length; i++) {
// ctx.fillText(text[i], x, y + (fontSize / 4) * (i+1) + 30 * i );
@ -37,7 +38,7 @@ function renderText(x, y, fontSize, text) {
}
function drawScoreboard() {
renderText(trueCanvas.width / 2, trueCanvas.height / 2, 50, score);
renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, 50, grey, score);
}
function clearGameBoard() {
@ -64,6 +65,7 @@ function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.strokeStyle = 'rgba(0,0,0,0)';
}
function showHighScores() {