From ca9c780bd723646348e4097bcb7300e4327865b2 Mon Sep 17 00:00:00 2001 From: logsol Date: Wed, 18 Jul 2012 15:29:19 +0200 Subject: [PATCH] joint - restructured common, client - added makebox function --- joint/client.js | 14 ++++++++++++++ joint/common.js | 50 ++++++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/joint/client.js b/joint/client.js index c12ac9c..b17d0b1 100644 --- a/joint/client.js +++ b/joint/client.js @@ -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; diff --git a/joint/common.js b/joint/common.js index 8c6583f..2bb06a6 100644 --- a/joint/common.js +++ b/joint/common.js @@ -46,21 +46,32 @@ function setupWorld(gravity) { world.CreateBody(bodyDef).CreateFixture(fixDef); // create some objects + + + 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.SetAsBox(0.5, 0.5); + + var bodyDef = new b2BodyDef; bodyDef.type = b2Body.b2_dynamicBody; + bodyDef.position.x = x; + bodyDef.position.y = y; - for(var i = 0; i < bodiesNum; i++) { - fixDef.shape = new b2PolygonShape; - fixDef.shape.SetAsBox(0.4, 0.4); + world.CreateBody(bodyDef).CreateFixture(fixDef); - bodyDef.position.x = ((i + 1) * 2) % 8; - bodyDef.position.y = 3; - - bodyDef.userData = { - 'bodyId': i + '' - }; - - world.CreateBody(bodyDef).CreateFixture(fixDef); - } + return bodyDef; } function jump() { @@ -68,17 +79,4 @@ function jump() { body.SetAwake(true); body.ApplyImpulse(new b2Vec2(8, -15), body.GetPosition()); 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; -} - +} \ No newline at end of file