holy crap wow how did we fix these merge conflicts

This commit is contained in:
Michael Yang 2014-05-17 17:15:55 -04:00
commit 0503349d92
2 changed files with 46 additions and 45 deletions

View file

@ -16,13 +16,12 @@ function Block(lane, color, distFromHex, settled) {
this.distFromHex = distFromHex; this.distFromHex = distFromHex;
} }
else { else {
this.distFromHex = 300; this.distFromHex = 470;
} }
this.draw = function() { this.draw = function() {
this.angle = 90 - (30 + 60 * this.lane);
this.width = 2 * this.distFromHex / Math.sqrt(3); this.width = 2 * this.distFromHex / Math.sqrt(3);
this.widthswag = this.width + this.height + 3; this.widthswag = this.width + this.height + 3;
var p1 = rotatePoint(-this.width/2, this.height/2, this.angle); var p1 = rotatePoint(-this.width/2, this.height/2, this.angle);
var p2 = rotatePoint(this.width/2, this.height/2, this.angle); var p2 = rotatePoint(this.width/2, this.height/2, this.angle);
var p3 = rotatePoint(this.widthswag/2, -this.height/2, this.angle); var p3 = rotatePoint(this.widthswag/2, -this.height/2, this.angle);
@ -61,23 +60,32 @@ var Clock = function(sideLength) {
this.addBlock = function(block) { this.addBlock = function(block) {
block.settled = 1; block.settled = 1;
var lane = 0; var lane = this.sides - block.lane;// -this.position;
lane += this.position + block.lane; lane += this.position;
lane = lane % this.sides; while (lane < 0) {
while(lane < 0) { lane += this.sides;
lane = lane + this.sides;
} }
lane = lane % this.sides;
block.distFromHex = MainClock.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; block.distFromHex = MainClock.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length;
this.blocks[lane].push(block); this.blocks[lane].push(block);
// consolidateBlocks(this,lane,this.blocks.length-1); // consolidateBlocks(this,lane,this.blocks.length-1);
}; };
this.doesBlockCollide = function(block, iter, index) { this.doesBlockCollide = function(block, iter) {
if (block.settled) return; if (block.settled) return;
var arr = this.blocks[(block.lane + this.position % this.sides) % this.sides];
var thisIn = index === undefined ? arr.length - 1 : index - 1; var lane = this.sides - block.lane;// -this.position;
lane += this.position;
while (lane < 0) {
lane += this.sides;
}
lane = lane % this.sides;
var arr = this.blocks[lane];
if (arr.length > 0) { if (arr.length > 0) {
if (block.distFromHex + iter - arr[thisIn].distFromHex - arr[thisIn].height <= 0) { if (block.distFromHex + iter - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) {
this.addBlock(block); this.addBlock(block);
} }
} }
@ -91,23 +99,19 @@ var Clock = function(sideLength) {
}; };
this.rotate = function(steps) { this.rotate = function(steps) {
var oldPosition = this.position;
this.position += steps; this.position += steps;
while (this.position < 0) {
this.position += 6;
}
this.position = this.position % this.sides; this.position = this.position % this.sides;
while(this.position < 0) { this.blocks.forEach(function(blocks){
this.position = this.position + this.sides; blocks.forEach(function(block){
} block.angle = block.angle - steps * 60;
for(var i=0; i<this.blocks.length; i++) { });
for(var j=0; j<this.blocks[i].length; j++) { });
this.blocks[i][j].lane += (this.position - oldPosition);
this.blocks[i][j].lane = this.blocks[i][j].lane % this.sides;
while(this.blocks[i][j].lane < 0) {
this.blocks[i][j].lane += this.sides;
}
}
}
this.angle = 30 + this.position * 60; this.angle = this.angle + steps * 60;
}; };
this.draw = function() { this.draw = function() {

35
main.js
View file

@ -1,10 +1,12 @@
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
var gameState = 1; // 0 - start, 1 - playing, 2 - end var gameState = 1; // 0 - start, 1 - playing, 2 - end
var framerate = 60; var framerate = 60;
ct = 0; ct = 0;
window.requestAnimFrame = (function(){ window.requestAnimFrame = (function(){
return window.requestAnimationFrame || return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame || window.webkitRequestAnimationFrame ||
@ -17,7 +19,6 @@ window.requestAnimFrame = (function(){
var clock = new Clock(6); var clock = new Clock(6);
var blocks = []; var blocks = [];
var MainClock = new Clock(65); var MainClock = new Clock(65);
var iter = 1; var iter = 1;
var lastGen = Date.now(); var lastGen = Date.now();
@ -25,7 +26,7 @@ var nextGen = 1000;
var colors = ["#e74c3c", "#f1c40f","#3498db"]; var colors = ["#e74c3c", "#f1c40f","#3498db"];
var hexagonBackgroundColor = '#ecf0f1'; var hexagonBackgroundColor = '#ecf0f1';
var swegBlue = '#2c3e50'; var swegBlue = '#2c3e50'; //tumblr?
function render() { function render() {
var now = Date.now(); var now = Date.now();
@ -37,31 +38,29 @@ function render() {
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
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, hexagonBackgroundColor);
var objectsToRemove = []; var objectsToRemove = [];
MainClock.blocks.forEach(function(hexBlocks){ var i;
for (var i = 0; i < hexBlocks.length; i++) { for (i in MainClock.blocks) {
MainClock.doesBlockCollide(hexBlocks[i], iter, i); for (var j = 0; j < MainClock.blocks[i].length; j++) {
if (!hexBlocks[i].settled) { var block = MainClock.blocks[i][j];
hexBlocks[i].distFromHex -= iter; MainClock.doesBlockCollide(block, iter);
} block.draw();
hexBlocks[i].draw();
} }
}); }
for (var i in blocks) { for (i in blocks) {
MainClock.doesBlockCollide(blocks[i], iter); MainClock.doesBlockCollide(blocks[i], iter);
if (!blocks[i].settled) { if (!blocks[i].settled) {
blocks[i].distFromHex -= iter; blocks[i].distFromHex -= iter;
} else { }
objectsToRemove.push(blocks[i]); else {
objectsToRemove.push(i);
} }
blocks[i].draw(); blocks[i].draw();
} }
objectsToRemove.forEach(function(o){ objectsToRemove.forEach(function(o){
blocks.splice(o,1); blocks.splice(o, 1);
}); });
ct++;
MainClock.draw(); MainClock.draw();
} }
@ -92,10 +91,8 @@ function drawPolygon(x, y, sides, radius, theta, color) { // can make more elega
} }
ctx.closePath(); ctx.closePath();
ctx.fill(); ctx.fill();
// console.log(ctx.fillStyle);
// ctx.strokeStyle = this.strokeColor;
// ctx.stroke();
}; };
function checkGameOver() { // fix font, fix size of hex function checkGameOver() { // fix font, fix size of hex
for(var i=0; i<MainClock.sides;i++) { for(var i=0; i<MainClock.sides;i++) {
if(MainClock.blocks[i].length>5) if(MainClock.blocks[i].length>5)