From d450e9056b834eee7242139713ffa7319579ad46 Mon Sep 17 00:00:00 2001 From: Noah Moroze Date: Sat, 17 May 2014 18:54:37 -0400 Subject: [PATCH 1/5] Gray line --- input.js | 1 + main.js | 22 ++++++++++++++++++---- math.js | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/input.js b/input.js index d18f0ea..89c7f60 100644 --- a/input.js +++ b/input.js @@ -7,3 +7,4 @@ keypress.register_combo({ keys: "right", on_keyup: function(){MainClock.rotate(-1)}, }); + diff --git a/main.js b/main.js index 235d0cc..4259f1b 100644 --- a/main.js +++ b/main.js @@ -37,7 +37,11 @@ function render() { if(now - lastGen > 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; @@ -71,6 +75,7 @@ function render() { blocks.splice(o, 1); }); MainClock.draw(); + drawPolygon(canvas.width/2, canvas.height/2, 6, 270, 30, "gray", false); } (function animloop(){ @@ -84,8 +89,14 @@ function render() { } })(); -function drawPolygon(x, y, sides, radius, theta, color) { // can make more elegant, reduce redundancy, fix readability - ctx.fillStyle = color; +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; + ctx.beginPath(); var coords = rotatePoint(0, radius, theta); ctx.moveTo(coords.x + x, coords.y + y); @@ -99,7 +110,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 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); +}; From db974845eaf4792928f68ad05963a8ee2f855da3 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sat, 17 May 2014 19:02:28 -0400 Subject: [PATCH 2/5] added overlays to modal screens --- input.js | 3 ++- main.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/input.js b/input.js index 0807461..848042a 100644 --- a/input.js +++ b/input.js @@ -9,10 +9,11 @@ keypress.register_combo({ }); keypress.register_combo({ - keys: "enter", + keys: "enter", on_keyup: function(){ if (gameState != 1) { init(); } + console.log('sweg'); }, }); diff --git a/main.js b/main.js index 60704a1..bad8c3b 100644 --- a/main.js +++ b/main.js @@ -37,10 +37,11 @@ function init() { lastGen = Date.now(); prevScore = Date.now(); nextGen = 1000; - + requestAnimFrame(animloop); } var colors = ["#e74c3c", "#f1c40f","#3498db"]; -var hexagonBackgroundColor = '#ecf0f1'; +var hexagonBackgroundColor = 'rgb(236, 240, 241)'; +var hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)'; var swegBlue = '#2c3e50'; //tumblr? function render() { @@ -85,13 +86,12 @@ function render() { MainClock.draw(); } -(function animloop(){ - requestAnimFrame(animloop); - +function animloop(){ if (gameState == 0) { showModal('Start!', 'Press enter to start!'); } else if (gameState == 1) { + requestAnimFrame(animloop); render(); checkGameOver(); } @@ -99,7 +99,9 @@ function render() { showModal('Game over!', score + ' pts!'); } -})(); +} +requestAnimFrame(animloop); + function drawPolygon(x, y, sides, radius, theta, color) { // can make more elegant, reduce redundancy, fix readability ctx.fillStyle = color; @@ -132,7 +134,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"'; From 79462e405e5d05b518a31b13e46d1feaa548754d Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sat, 17 May 2014 19:06:51 -0400 Subject: [PATCH 3/5] edited end screen message --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index bad8c3b..310c319 100644 --- a/main.js +++ b/main.js @@ -96,7 +96,7 @@ function animloop(){ checkGameOver(); } else if (gameState == 2) { - showModal('Game over!', score + ' pts!'); + showModal('Game over: '+score+' pts!', 'Press enter to restart!'); } } From ab48e918b81bb3e2017f80f8b36024cd0c825dc4 Mon Sep 17 00:00:00 2001 From: garrettdreyfus Date: Sat, 17 May 2014 19:16:55 -0400 Subject: [PATCH 4/5] 4 in a row --- checking.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/checking.js b/checking.js index 722c65f..69f4151 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 Date: Sat, 17 May 2014 19:17:28 -0400 Subject: [PATCH 5/5] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md 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