HTML and CSS Reference
In-Depth Information
fixDef.shape = new b2PolygonShape();
fixDef.shape.SetAsBox(5/pxPerMeter, 5/pxPerMeter);
var body = this.world.CreateBody(bodyDef);
body.CreateFixture(fixDef);
bodyDef.type = b2Body.b2_staticBody;
bodyDef.position.x = (hoopX+45)/pxPerMeter;
bodyDef.position.y = hoopY/pxPerMeter;
bodyDef.angle = 0;
fixDef.shape = new b2PolygonShape();
fixDef.shape.SetAsBox(5/pxPerMeter, 5/pxPerMeter);
body = this.world.CreateBody(bodyDef);
body.CreateFixture(fixDef);
// hoop board dimension: 10x80 (5x40 in half value)
bodyDef.type = b2Body.b2_staticBody;
bodyDef.position.x = (hoopX-5)/pxPerMeter;
bodyDef.position.y = (hoopY-40)/pxPerMeter;
bodyDef.angle = 0;
fixDef.shape = new b2PolygonShape();
fixDef.shape.SetAsBox(5/pxPerMeter, 40/pxPerMeter);
fixDef.restitution = 0.05;
var board = this.world.CreateBody(bodyDef);
board.CreateFixture(fixDef);
};
7. Now, we can iniialize the world by calling the
createLevel
method. At the
same ime, we should remove the creaion of two test objects that we added
in the last task:
game.physics.createLevel();
8. In the
game.js
file, we handle the
mousedown
and
mouseup
events to get
the posiion of the cursor and the duraion for which the mouse buton was
kept pressed. The cursor's posiion determines the angle and the duraion
determines the power:
isPlaying = true;
game.tickWhenDown = 0;
game.tickWhenUp = 0;