holy crap wow how did we fix these merge conflicts
This commit is contained in:
commit
0503349d92
2 changed files with 46 additions and 45 deletions
56
entities.js
56
entities.js
|
@ -16,13 +16,12 @@ function Block(lane, color, distFromHex, settled) {
|
|||
this.distFromHex = distFromHex;
|
||||
}
|
||||
else {
|
||||
this.distFromHex = 300;
|
||||
this.distFromHex = 470;
|
||||
}
|
||||
this.draw = function() {
|
||||
this.angle = 90 - (30 + 60 * this.lane);
|
||||
|
||||
this.width = 2 * this.distFromHex / Math.sqrt(3);
|
||||
this.widthswag = this.width + this.height + 3;
|
||||
|
||||
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.widthswag/2, -this.height/2, this.angle);
|
||||
|
@ -61,23 +60,32 @@ var Clock = function(sideLength) {
|
|||
|
||||
this.addBlock = function(block) {
|
||||
block.settled = 1;
|
||||
var lane = 0;
|
||||
lane += this.position + block.lane;
|
||||
lane = lane % this.sides;
|
||||
while(lane < 0) {
|
||||
lane = lane + this.sides;
|
||||
var lane = this.sides - block.lane;// -this.position;
|
||||
lane += this.position;
|
||||
while (lane < 0) {
|
||||
lane += this.sides;
|
||||
}
|
||||
lane = lane % this.sides;
|
||||
block.distFromHex = MainClock.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length;
|
||||
this.blocks[lane].push(block);
|
||||
// consolidateBlocks(this,lane,this.blocks.length-1);
|
||||
};
|
||||
|
||||
this.doesBlockCollide = function(block, iter, index) {
|
||||
this.doesBlockCollide = function(block, iter) {
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
|
@ -91,23 +99,19 @@ var Clock = function(sideLength) {
|
|||
};
|
||||
|
||||
this.rotate = function(steps) {
|
||||
var oldPosition = this.position;
|
||||
this.position += steps;
|
||||
while (this.position < 0) {
|
||||
this.position += 6;
|
||||
}
|
||||
|
||||
this.position = this.position % this.sides;
|
||||
while(this.position < 0) {
|
||||
this.position = this.position + this.sides;
|
||||
}
|
||||
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.blocks.forEach(function(blocks){
|
||||
blocks.forEach(function(block){
|
||||
block.angle = block.angle - steps * 60;
|
||||
});
|
||||
});
|
||||
|
||||
this.angle = 30 + this.position * 60;
|
||||
this.angle = this.angle + steps * 60;
|
||||
};
|
||||
|
||||
this.draw = function() {
|
||||
|
|
35
main.js
35
main.js
|
@ -1,10 +1,12 @@
|
|||
var canvas = document.getElementById('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var gameState = 1; // 0 - start, 1 - playing, 2 - end
|
||||
var framerate = 60;
|
||||
|
||||
|
||||
ct = 0;
|
||||
|
||||
window.requestAnimFrame = (function(){
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
|
@ -17,7 +19,6 @@ window.requestAnimFrame = (function(){
|
|||
var clock = new Clock(6);
|
||||
|
||||
var blocks = [];
|
||||
|
||||
var MainClock = new Clock(65);
|
||||
var iter = 1;
|
||||
var lastGen = Date.now();
|
||||
|
@ -25,7 +26,7 @@ var nextGen = 1000;
|
|||
|
||||
var colors = ["#e74c3c", "#f1c40f","#3498db"];
|
||||
var hexagonBackgroundColor = '#ecf0f1';
|
||||
var swegBlue = '#2c3e50';
|
||||
var swegBlue = '#2c3e50'; //tumblr?
|
||||
|
||||
function render() {
|
||||
var now = Date.now();
|
||||
|
@ -37,31 +38,29 @@ function render() {
|
|||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
drawPolygon(canvas.width / 2, canvas.height / 2, 6, canvas.width / 2, 30, hexagonBackgroundColor);
|
||||
var objectsToRemove = [];
|
||||
MainClock.blocks.forEach(function(hexBlocks){
|
||||
for (var i = 0; i < hexBlocks.length; i++) {
|
||||
MainClock.doesBlockCollide(hexBlocks[i], iter, i);
|
||||
if (!hexBlocks[i].settled) {
|
||||
hexBlocks[i].distFromHex -= iter;
|
||||
}
|
||||
|
||||
hexBlocks[i].draw();
|
||||
var i;
|
||||
for (i in MainClock.blocks) {
|
||||
for (var j = 0; j < MainClock.blocks[i].length; j++) {
|
||||
var block = MainClock.blocks[i][j];
|
||||
MainClock.doesBlockCollide(block, iter);
|
||||
block.draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (var i in blocks) {
|
||||
for (i in blocks) {
|
||||
MainClock.doesBlockCollide(blocks[i], iter);
|
||||
if (!blocks[i].settled) {
|
||||
blocks[i].distFromHex -= iter;
|
||||
} else {
|
||||
objectsToRemove.push(blocks[i]);
|
||||
}
|
||||
else {
|
||||
objectsToRemove.push(i);
|
||||
}
|
||||
blocks[i].draw();
|
||||
}
|
||||
|
||||
objectsToRemove.forEach(function(o){
|
||||
blocks.splice(o,1);
|
||||
blocks.splice(o, 1);
|
||||
});
|
||||
ct++;
|
||||
MainClock.draw();
|
||||
}
|
||||
|
||||
|
@ -92,10 +91,8 @@ function drawPolygon(x, y, sides, radius, theta, color) { // can make more elega
|
|||
}
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
// console.log(ctx.fillStyle);
|
||||
// ctx.strokeStyle = this.strokeColor;
|
||||
// ctx.stroke();
|
||||
};
|
||||
|
||||
function checkGameOver() { // fix font, fix size of hex
|
||||
for(var i=0; i<MainClock.sides;i++) {
|
||||
if(MainClock.blocks[i].length>5)
|
||||
|
|
Loading…
Reference in a new issue