fixed block width calculation

This commit is contained in:
Michael Yang 2014-05-17 13:34:57 -04:00
parent b4877c3e97
commit 2bc6560ba4

14
main.js
View file

@ -71,7 +71,7 @@ function Block(lane, color, distFromHex) {
this.distFromHex = 300;
}
this.draw = function() {
this.width = this.distFromHex;
this.width = 2 * this.distFromHex / Math.sqrt(3) + this.height;
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);
@ -90,12 +90,12 @@ function Block(lane, color, distFromHex) {
ctx.closePath();
ctx.fill();
ctx.strokeStyle = '#322'
ctx.beginPath();
ctx.moveTo(canvas.width/2, canvas.height/2);
ctx.lineTo(canvas.width/2 + Math.sin((this.angle) * (Math.PI/180)) * (this.distFromHex + this.height), canvas.height/2 - Math.cos((this.angle) * (Math.PI/180)) * (this.distFromHex + this.height));
ctx.closePath();
ctx.stroke();
// ctx.strokeStyle = '#322'
// ctx.beginPath();
// ctx.moveTo(canvas.width/2, canvas.height/2);
// ctx.lineTo(canvas.width/2 + Math.sin((this.angle) * (Math.PI/180)) * (this.distFromHex + this.height), canvas.height/2 - Math.cos((this.angle) * (Math.PI/180)) * (this.distFromHex + this.height));
// ctx.closePath();
// ctx.stroke();
};
}