2016-03-23 22:59:54 -04:00
|
|
|
var expect = require('./testutil/expect');
|
|
|
|
|
var sinon = require('sinon');
|
|
|
|
|
|
|
|
|
|
var Vec2 = require('../lib/common/Vec2');
|
|
|
|
|
var Circle = require('../lib/shape/CircleShape');
|
|
|
|
|
var Body = require('../lib/Body');
|
|
|
|
|
var Fixture = require('../lib/Fixture');
|
|
|
|
|
var World = require('../lib/World');
|
|
|
|
|
|
|
|
|
|
describe('Basic', function() {
|
|
|
|
|
|
|
|
|
|
it('World', function() {
|
|
|
|
|
|
|
|
|
|
var world = new World();
|
|
|
|
|
|
|
|
|
|
var circle = new Circle(1);
|
|
|
|
|
|
|
|
|
|
var b1 = world.createBody({
|
|
|
|
|
position : Vec2(0, 0),
|
|
|
|
|
type : 'dynamic'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
b1.createFixture(circle);
|
|
|
|
|
|
|
|
|
|
expect(b1.getFixtureList().getType()).be('circle');
|
|
|
|
|
expect(b1.getWorld()).be(world);
|
|
|
|
|
expect(world.getBodyList()).be(b1);
|
|
|
|
|
|
|
|
|
|
b1.applyForceToCenter(Vec2(1, 0), true);
|
|
|
|
|
|
|
|
|
|
var b2 = world.createBody({
|
|
|
|
|
position : Vec2(2, 0),
|
|
|
|
|
type : 'dynamic'
|
2017-03-17 23:52:32 -04:00
|
|
|
});
|
2016-03-23 22:59:54 -04:00
|
|
|
b2.createFixture(circle);
|
|
|
|
|
b2.applyForceToCenter(Vec2(-1, 0), true);
|
|
|
|
|
|
|
|
|
|
world.step(1 / 20);
|
|
|
|
|
|
|
|
|
|
// console.log(b2.getPosition());
|
|
|
|
|
|
|
|
|
|
var p = b1.getPosition();
|
2017-03-17 23:52:32 -04:00
|
|
|
expect(p.x).near(0.0);
|
2016-03-23 22:59:54 -04:00
|
|
|
expect(p.y).near(0.0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|