diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca92304 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Hextris +========== + +Built by @teamsnowman (@meadowstream, @garrettdreyfus, @nmoroze, and @themichaelyang) for HackExeter 2014 diff --git a/checking.js b/checking.js index f06606d..4fd7cbd 100644 --- a/checking.js +++ b/checking.js @@ -74,10 +74,22 @@ function eraseBlocks(clock,deleted) { side = deleted[0][0]; index = deleted[0][1]; horizontal = deleted[0][2]; - for(var i=0;i<3;i++) { + length =3; + flag=0; + if(clock.blocks[getIndex(clock.blocks,side+horizontal+length+1)][index]){ + flag= clock.blocks[getIndex(clock.blocks,side+horizontal+length)][index].color == clock.blocks[getIndex(clock.blocks,side+horizontal+length+1)][index].color; + } + while(flag) { + if(clock.blocks[getIndex(clock.blocks,side+horizontal+length+1)][index]){ + flag= clock.blocks[getIndex(clock.blocks,side+horizontal+length)][index].color == clock.blocks[getIndex(clock.blocks,side+horizontal+length+1)][index].color; + } + length++; + } + console.log(length); + for(var i=0;i0))); for(var i=0; i0){ - for(var i=0;i<3;i++) { + for(var i=0;i nextGen) { blocks.push(new Block(randInt(0, 6), colors[randInt(0, colors.length)])); lastGen = Date.now(); - nextGen = randInt(500/iter, 1500/iter); + var minTime = 500/iter; + if(minTime < 100) { + minTime = 100; + } + nextGen = randInt(minTime, 1500/iter); } if(now - prevScore > 1000) { score += 5 * (scoreScalar * scoreAdditionCoeff); @@ -87,26 +92,34 @@ function render() { blocks.splice(o, 1); }); MainClock.draw(); + drawPolygon(canvas.width/2, canvas.height/2, 6, 270, 30, "gray", false); } -(function animloop(){ - requestAnimFrame(animloop); - +function animloop(){ if (gameState == 0) { showModal('Start!', 'Press enter to start!'); } else if (gameState == 1) { + requestAnimFrame(animloop); render(); checkGameOver(); } else if (gameState == 2) { - showModal('Game over!', score + ' pts!'); + showModal('Game over: '+score+' pts!', 'Press enter to restart!'); } -})(); +} +requestAnimFrame(animloop); + + +function drawPolygon(x, y, sides, radius, theta, color, fill) { // can make more elegant, reduce redundancy, fix readability + if(fill==undefined) + fill = true; + if(fill) + ctx.fillStyle = color; + else + ctx.strokeStyle = color; -function drawPolygon(x, y, sides, radius, theta, color) { // can make more elegant, reduce redundancy, fix readability - ctx.fillStyle = color; ctx.beginPath(); var coords = rotatePoint(0, radius, theta); ctx.moveTo(coords.x + x, coords.y + y); @@ -120,7 +133,10 @@ function drawPolygon(x, y, sides, radius, theta, color) { // can make more elega oldY = coords.y; } ctx.closePath(); - ctx.fill(); + if(fill) + ctx.fill(); + else + ctx.stroke(); }; function checkGameOver() { // fix font, fix size of hex @@ -136,7 +152,7 @@ function showModal(text, secondaryText) { var buttonSize = 150; var fontSizeLarge = 50; var fontSizeSmall = 25; - drawPolygon(canvas.width / 2, canvas.height / 2, 6, canvas.width / 2, 30, hexagonBackgroundColor); + drawPolygon(canvas.width / 2, canvas.height / 2, 6, canvas.width / 2, 30, hexagonBackgroundColorClear); ctx.fillStyle = swegBlue; // drawPolygon(canvas.width / 2, canvas.height / 2, 6, buttonSize, 30, swegBlue); ctx.font = fontSizeLarge+'px "Roboto"'; diff --git a/math.js b/math.js index e3184ff..c74f052 100644 --- a/math.js +++ b/math.js @@ -13,3 +13,22 @@ function randInt(min, max) { return Math.floor((Math.random() * max) + min); } +//http://stackoverflow.com/questions/15397036/drawing-dashed-lines-on-html5-canvas +CanvasRenderingContext2D.prototype.dashedLine = function (x1, y1, x2, y2, dashLen) { + if (dashLen == undefined) dashLen = 2; + this.moveTo(x1, y1); + + var dX = x2 - x1; + var dY = y2 - y1; + var dashes = Math.floor(Math.sqrt(dX * dX + dY * dY) / dashLen); + var dashX = dX / dashes; + var dashY = dY / dashes; + + var q = 0; + while (q++ < dashes) { + x1 += dashX; + y1 += dashY; + this[q % 2 == 0 ? 'moveTo' : 'lineTo'](x1, y1); + } + this[q % 2 == 0 ? 'moveTo' : 'lineTo'](x2, y2); +};