This commit is contained in:
meadowstream 2014-05-17 19:21:22 -04:00
commit 0f1633fe8f
5 changed files with 72 additions and 16 deletions

4
README.md Normal file
View file

@ -0,0 +1,4 @@
Hextris
==========
Built by @teamsnowman (@meadowstream, @garrettdreyfus, @nmoroze, and @themichaelyang) for HackExeter 2014

View file

@ -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;i<length;i++) {
clock.blocks[getIndex(clock.blocks,side+horizontal+i)].splice(index,1);
}
for(var i=0;i<3;i++) {
for(var i=0;i<length;i++) {
if(side+horizontal+i<clock.blocks.length) {
consolidateBlocks(clock,getIndex(clock.blocks,side+horizontal+i),index);
}
@ -87,6 +99,10 @@ function eraseBlocks(clock,deleted) {
side = deleted[1][0];
index = deleted[1][1];
vertical = deleted[1][2];
vertlength=3;
while(index+vertical+vertlength<clock.blocks[side].length-1 && (clock.blocks[slide][index+vertical+length].color ==clock.blocks[slide][index+vertical+length+1].color )) {
vertlength+=1;
}
clock.blocks[side].splice(index+vertical,2+(1*(!deleted[0].length>0)));
for(var i=0; i<clock.blocks[side].length-(index+vertical); i++) {
consolidateBlocks(clock,side,index+vertical+i);
@ -99,7 +115,7 @@ function eraseBlocks(clock,deleted) {
}
}
if(deleted[0].length>0){
for(var i=0;i<3;i++) {
for(var i=0;i<length;i++) {
if(deleted[0][2] != "false" ) {
sidesChanged.push(getIndex(clock.blocks,deleted[0][0]+deleted[0][2]+i));
}

View file

@ -9,11 +9,12 @@ keypress.register_combo({
});
keypress.register_combo({
keys: "enter",
keys: "enter",
on_keyup: function(){
if (gameState != 1) {
init();
}
console.log('sweg');
},
});

40
main.js
View file

@ -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?
var scoreAdditionCoeff = 1;
@ -50,7 +51,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 * 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"';

19
math.js
View file

@ -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);
};