Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tracklength measured on all balls

  • Loading branch information...
commit 286b23e6c9ef74a74a36befcaef5f532c9c18f73 1 parent 5ceab9a
@egraether egraether authored
View
11 public/javascripts/marblerun/bricks/ball.js
@@ -7,7 +7,6 @@ var Ball = Class.create(Brick, {
this.positionVector = new b2Vec2();
this.velocityVector = new b2Vec2();
- this.rollLength = 0;
this.lastPosition = new b2Vec2();
this.isDraggable = false;
@@ -37,16 +36,15 @@ var Ball = Class.create(Brick, {
}
var difference = this.minus(this.lastPosition, this.body.GetPosition());
- this.rollLength += difference.Length();
+ this.parent.trackLength += difference.Length() / 10;
this.lastPosition.Set(this.body.GetPosition().x, this.body.GetPosition().y);
- if (this.rollLength > 9999) {
- this.rollLength = 9999;
+ if (this.parent.trackLength > 9999) {
+ this.parent.trackLength = 9999;
}
- $('lengthDisplay').update(this.getFormatString(this.rollLength));
- this.parent.trackLength = this.rollLength / 10;
+ $('lengthDisplay').update(this.getFormatString(this.parent.trackLength * 10));
},
@@ -69,7 +67,6 @@ var Ball = Class.create(Brick, {
},
reset: function() {
- this.rollLength = 0;
this.lastPosition.Set(this.cell.col + 0.5, this.cell.row + 0.5);
View
32 public/javascripts/marblerun/bricks/ballbox.js
@@ -4,7 +4,6 @@ var BallBox = Class.create(Brick, {
$super();
this.ball = new Ball();
- this.trackLength = null;
this.timeoutID = 0;
},
@@ -40,26 +39,15 @@ var BallBox = Class.create(Brick, {
},
- createShapes: function(body) {
- var shapeDefinition = new b2PolygonDef();
-
- shapeDefinition.vertexCount = 4;
- shapeDefinition.restitution = 0;
- shapeDefinition.friction = 0.9;
-
- shapeDefinition.vertices[0].Set(-0.5, -0.5);
- shapeDefinition.vertices[1].Set(0.5, -0.5);
- shapeDefinition.vertices[2].Set(0.5, 0.5);
- shapeDefinition.vertices[3].Set(-0.5, 0.5);
-
- body.CreateShape(shapeDefinition);
+ createBody: function($super, world) {
+ $super(world);
+
var myScope = this;
-
- body.onCollision = function(contact) {
+
+ this.body.onCollision = function(contact) {
myScope.onCollision(contact);
};
-
},
drawShape: function(context) {
@@ -124,15 +112,20 @@ var BallBox = Class.create(Brick, {
context.lineTo(Brick.SIZE * 2 / 7, Brick.SIZE * 5 / 14);
context.closePath();
- context.stroke();
-
+
if (!this.ball.body) {
+ context.save();
+
context.fillStyle = "#800000";
context.fill();
+ context.restore();
+
}
+ context.stroke();
+
}
},
@@ -156,7 +149,6 @@ var BallBox = Class.create(Brick, {
this.ball.y = this.y;
offset.Add(this.ball.body.GetPosition());
- //offset = this.ball.body.GetPosition();
this.ball.body.SetXForm(offset, 0);
this.ball.impulseVector.Add(this.rotateVector(shootVector, this.body.GetAngle()));
Please sign in to comment.
Something went wrong with that request. Please try again.