topical media & game development

talk show tell print

#javascript-physics-demos-demo-base.js / js



  function createWorld() {
          var worldAABB = new b2AABB();
          worldAABB.minVertex.Set(-1000, -1000);
          worldAABB.maxVertex.Set(1000, 1000);
          var gravity = new b2Vec2(0, 300);
          var doSleep = true;
          var world = new b2World(worldAABB, gravity, doSleep);
          createGround(world);
          createBox(world, 0, 125, 10, 250);
          createBox(world, 500, 125, 10, 250);
          return world;
  }
  
  function createGround(world) {
          var groundSd = new b2BoxDef();
          groundSd.extents.Set(1000, 50);
          groundSd.restitution = 0.2;
          var groundBd = new b2BodyDef();
          groundBd.AddShape(groundSd);
          groundBd.position.Set(-500, 340);
          return world.CreateBody(groundBd)
  }
  
  function createBall(world, x, y) {
          var ballSd = new b2CircleDef();
          ballSd.density = 1.0;
          ballSd.radius = 20;
          ballSd.restitution = 1.0;
          ballSd.friction = 0;
          var ballBd = new b2BodyDef();
          ballBd.AddShape(ballSd);
          ballBd.position.Set(x,y);
          return world.CreateBody(ballBd);
  }
  
  function createBox(world, x, y, width, height, fixed) {
          if (typeof(fixed) == 'undefined') fixed = true;
          var boxSd = new b2BoxDef();
          if (!fixed) boxSd.density = 1.0;
          boxSd.extents.Set(width, height);
          var boxBd = new b2BodyDef();
          boxBd.AddShape(boxSd);
          boxBd.position.Set(x,y);
          return world.CreateBody(boxBd)
  }
  
  var demos = {};
  demos.InitWorlds = [];
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.