This commit is contained in:
Noah Moroze 2014-05-17 12:42:02 -04:00
commit 14e6c357ba
3 changed files with 149 additions and 1 deletions

88
checking.js Normal file
View file

@ -0,0 +1,88 @@
function getIndex(list,index)
{
if(index>-1)
return index%list.length;
else
return list.length+index;
}
function scoreCheckHorizontal(clock,side,index) {
clockSides = clock.blocks;
clockSides[0];
if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side-1)][index] && clockSides[getIndex(clockSides,side-2)][index]) {
if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side-1)][index].color&& clockSides[getIndex(clockSides,side-1)][index].color === clockSides[getIndex(clockSides,side-2)][index].color) {
return -2;
}
}
if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side+1)][index] && clockSides[getIndex(clockSides,side-1)][index]) {
if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side+1)][index].color&& clockSides[getIndex(clockSides,side+1)][index].color === clockSides[getIndex(clockSides,side-1)][index].color) {
return -1;
}
}
if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side+1)][index] && clockSides[getIndex(clockSides,side+2)][index]) {
if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side+1)][index].color&& clockSides[getIndex(clockSides,side+1)][index].color === clockSides[getIndex(clockSides,side+2)][index].color) {
return 0;
}
}
return "false";
}
function scoreCheckVertical(clock,side,index) {
curSide = clock.blocks[side];
if(curSide[index] && curSide[index-2] && curSide[index-1]) {
if(curSide[index].color == curSide[index-2].color && curSide[index-2].color ==curSide[index-1].color) {
return -2;
}
}
if(curSide[index] && curSide[index+1] && curSide[index-1]) {
if(curSide[index].color == curSide[index+1].color && curSide[index+1].color == curSide[index-1].color) {
return -1;
}
}
if(curSide[index] && curSide[index+2] && curSide[index+1]) {
if(curSide[index].color == curSide[index+2].color&& curSide[index+2].color ==curSide[index+1].color) {
return 0;
}
}
return "false";
}
function consolidateBlocks(clock,side,index) {
horizontal = scoreCheckHorizontal(clock,side,index);
vertical = scoreCheckVertical(clock,side,index);
deleted = [];
if(horizontal != "false") {
deleted.push([side,index,horizontal]);
}
else {
deleted.push([]);
}
if(vertical != "false") {
deleted.push([side,index,vertical]);
}
else {
deleted.push([]);
}
eraseBlocks(clock,deleted);
}
function eraseBlocks(clock,deleted) {
if(deleted[0].length>0){
side = deleted[0][0];
index = deleted[0][1];
horizontal = deleted[0][2];
for(var i=0;i<3;i++) {
clock.blocks[getIndex(clock.sides,side+horizontal+i)].splice(index,1);
}
for(var i=0;i<3;i++) {
consolidateBlocks(clock,side+horizontal+i,index);
}
}
if(deleted[1].length>0){
side = deleted[1][0];
index = deleted[1][1];
vertical = deleted[1][2];
clock.blocks[side].splice(index+vertical,3);
consolidateBlocks(clock,side,index+vertical);
}
}

View file

@ -5,7 +5,7 @@
</head>
<body>
<center>
<canvas id="canvas" style='border: 1px black solid;' width='1000' height='1000'></canvas>
<canvas id="canvas" width = '700' height = '700' style='background-color:rgba(23,23,23, 1)'></canvas>
</center>
<script src="math.js"></script>
<script src="entities.js"></script>

60
main.js
View file

@ -14,6 +14,65 @@ clock = new Clock(6);
var blocks = [];
<<<<<<< HEAD
for (var i = 0; i < 12; i++) {
blocks.push(new Block(i, 'green'));
}
function Render() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
blocks.forEach(function(o){
o.draw();
o.distFromHex -= 1/100;
});
requestAnimFrame(Render);
}
(function animloop(){
requestAnimFrame(animloop);
Render();
})();
function Block(lane, color, distFromHex) {
this.height = 20;
this.width = 65;
this.lane = lane;
this.angle = 90 - (30 + 60 * lane);
if (this.angle < 0) {
this.angle += 360;
}
this.color = color;
if (distFromHex) {
this.distFromHex = distFromHex;
}
else {
this.distFromHex = 300;
}
this.draw = function() {
var p1 = rotatePoint(-this.width/2, this.height/2, this.angle);
var p2 = rotatePoint(this.width/2, this.height/2, this.angle);
var p3 = rotatePoint(this.width/2, -this.height/2, this.angle);
var p4 = rotatePoint(-this.width/2, -this.height/2, this.angle);
ctx.fillStyle="#FF0000";
var baseX = canvas.width/2 + Math.sin((this.angle) * (Math.PI/180)) * (this.distFromHex);
var baseY = canvas.height/2 - Math.cos((this.angle) * (Math.PI/180)) * (this.distFromHex);
ctx.beginPath();
ctx.moveTo(baseX + p1.x, baseY + p1.y);
ctx.lineTo(baseX + p2.x, baseY + p2.y);
ctx.lineTo(baseX + p3.x, baseY + p3.y);
ctx.lineTo(baseX + p4.x, baseY + p4.y);
ctx.lineTo(baseX + p1.x, baseY + p1.y);
ctx.closePath();
ctx.fill();
};
}
=======
// for (var i = 0; i < 6; i++) {
// blocks.push(new Block(i, 'green'));
// }
@ -69,3 +128,4 @@ function Render() {
// }
// }
>>>>>>> cf79fbefde53e6994623e30795f806aa8efdb4d9