joint - restructured common, client - added makebox function

This commit is contained in:
logsol 2012-07-18 15:29:19 +02:00
parent 5898f29167
commit ca9c780bd7
2 changed files with 38 additions and 26 deletions

View file

@ -52,4 +52,18 @@ function getElementPosition(element) {
} }
} }
function findBody(index) {
var body = null;
var nextBody = world.GetBodyList();
for (var i = 0; i < bodiesNum; i++) {
if (nextBody.GetUserData().bodyId == index) { body = nextBody; break; }
nextBody = nextBody.GetNext();
}
return body;
}
window.onload = init; window.onload = init;

View file

@ -46,21 +46,32 @@ function setupWorld(gravity) {
world.CreateBody(bodyDef).CreateFixture(fixDef); world.CreateBody(bodyDef).CreateFixture(fixDef);
// create some objects // create some objects
bodyDef.type = b2Body.b2_dynamicBody;
for(var i = 0; i < bodiesNum; i++) {
var b1 = makeBox(2,3);
var b2 = makeBox(3,3);
}
function makeBox(x, y){
var fixDef = new b2FixtureDef;
fixDef.density = 1.0;
fixDef.friction = 0.99;
fixDef.restitution = .51;
fixDef.shape = new b2PolygonShape; fixDef.shape = new b2PolygonShape;
fixDef.shape.SetAsBox(0.4, 0.4); fixDef.shape.SetAsBox(0.5, 0.5);
bodyDef.position.x = ((i + 1) * 2) % 8; var bodyDef = new b2BodyDef;
bodyDef.position.y = 3; bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = x;
bodyDef.userData = { bodyDef.position.y = y;
'bodyId': i + ''
};
world.CreateBody(bodyDef).CreateFixture(fixDef); world.CreateBody(bodyDef).CreateFixture(fixDef);
}
return bodyDef;
} }
function jump() { function jump() {
@ -69,16 +80,3 @@ function jump() {
body.ApplyImpulse(new b2Vec2(8, -15), body.GetPosition()); body.ApplyImpulse(new b2Vec2(8, -15), body.GetPosition());
body.SetAngularVelocity(1.5); body.SetAngularVelocity(1.5);
} }
function findBody(index) {
var body = null;
var nextBody = world.GetBodyList();
for (var i = 0; i < bodiesNum; i++) {
if (nextBody.GetUserData().bodyId == index) { body = nextBody; break; }
nextBody = nextBody.GetNext();
}
return body;
}