Merge branch 'master' of https://github.com/teamsnowman/wastedtime
This commit is contained in:
commit
7a2a860966
4 changed files with 84 additions and 16 deletions
20
checking.js
20
checking.js
|
@ -66,7 +66,9 @@ function consolidateBlocks(clock,side,index) {
|
|||
deleted.push([]);
|
||||
}
|
||||
eraseBlocks(clock,deleted);
|
||||
return
|
||||
}
|
||||
|
||||
function eraseBlocks(clock,deleted) {
|
||||
if(deleted[0].length>0){
|
||||
side = deleted[0][0];
|
||||
|
@ -90,4 +92,22 @@ function eraseBlocks(clock,deleted) {
|
|||
consolidateBlocks(clock,side,index+vertical+i);
|
||||
}
|
||||
}
|
||||
sidesChanged = [];
|
||||
if(deleted[1].length>0){
|
||||
if(deleted[1][0] != "false") {
|
||||
sidesChanged.push(deleted[1][0]);
|
||||
}
|
||||
}
|
||||
if(deleted[0].length>0){
|
||||
for(var i=0;i<3;i++) {
|
||||
if(deleted[0][2] != "false" ) {
|
||||
sidesChanged.push(getIndex(clock.blocks,deleted[0][0]+deleted[0][2]+i));
|
||||
}
|
||||
}
|
||||
}
|
||||
sidesChanged.forEach(function(o){
|
||||
MainClock.blocks[o].forEach(function(block) {
|
||||
block.settled = 0;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
34
entities.js
34
entities.js
|
@ -1,5 +1,4 @@
|
|||
//you can change these to sexier stuff
|
||||
|
||||
function Block(lane, color, distFromHex, settled) {
|
||||
this.settled = (settled == undefined) ? 0 : 1;
|
||||
this.height = 20;
|
||||
|
@ -18,6 +17,7 @@ function Block(lane, color, distFromHex, settled) {
|
|||
else {
|
||||
this.distFromHex = 300;
|
||||
}
|
||||
|
||||
this.draw = function() {
|
||||
this.width = 2 * this.distFromHex / Math.sqrt(3);
|
||||
this.widthswag = this.width + this.height + 3;
|
||||
|
@ -43,7 +43,7 @@ function Block(lane, color, distFromHex, settled) {
|
|||
|
||||
}
|
||||
|
||||
var Clock = function(sideLength) {
|
||||
function Clock(sideLength) {
|
||||
this.fillColor = '#2c3e50';
|
||||
this.position = 0;
|
||||
this.sides = 6;
|
||||
|
@ -71,7 +71,7 @@ var Clock = function(sideLength) {
|
|||
consolidateBlocks(this,lane,this.blocks[lane].length-1);
|
||||
};
|
||||
|
||||
this.doesBlockCollide = function(block, iter) {
|
||||
this.doesBlockCollide = function(block, iter, position, tArr) {
|
||||
if (block.settled) return;
|
||||
|
||||
var lane = this.sides - block.lane;// -this.position;
|
||||
|
@ -81,21 +81,33 @@ var Clock = function(sideLength) {
|
|||
lane += this.sides;
|
||||
}
|
||||
lane = lane % this.sides;
|
||||
|
||||
var arr = this.blocks[lane];
|
||||
|
||||
if (arr.length > 0) {
|
||||
if (block.distFromHex + iter - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) {
|
||||
this.addBlock(block);
|
||||
if (position !== undefined) {
|
||||
arr = tArr;
|
||||
if (position <= 0) {
|
||||
if (block.distFromHex - (this.sideLength/2) * Math.sqrt(3) <= 0) {
|
||||
block.settled = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (block.distFromHex + iter - arr[position - 1].distFromHex - arr[position - 1].height <= 0) {
|
||||
block.settled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (block.distFromHex - (this.sideLength/2) * Math.sqrt(3) <= 0) {
|
||||
this.addBlock(block);
|
||||
if (arr.length > 0) {
|
||||
if (block.distFromHex + iter - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) {
|
||||
this.addBlock(block);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (block.distFromHex + iter - (this.sideLength/2) * Math.sqrt(3) <= 0) {
|
||||
this.addBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.rotate = function(steps) {
|
||||
|
|
27
main.js
27
main.js
|
@ -50,7 +50,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;
|
||||
|
@ -64,7 +68,10 @@ function render() {
|
|||
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);
|
||||
MainClock.doesBlockCollide(block, iter, j, MainClock.blocks[i]);
|
||||
if (!MainClock.blocks[i][j].settled) {
|
||||
MainClock.blocks[i][j].distFromHex -= iter;
|
||||
}
|
||||
block.draw();
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +91,7 @@ function render() {
|
|||
blocks.splice(o, 1);
|
||||
});
|
||||
MainClock.draw();
|
||||
drawPolygon(canvas.width/2, canvas.height/2, 6, 270, 30, "gray", false);
|
||||
}
|
||||
|
||||
function animloop(){
|
||||
|
@ -103,8 +111,14 @@ function animloop(){
|
|||
requestAnimFrame(animloop);
|
||||
|
||||
|
||||
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);
|
||||
|
@ -118,7 +132,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
|
||||
|
|
19
math.js
19
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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue