Physics: box2d
box2d
Box2D pyhysics for your games
import
_ @sys.box2d;
box2d.reset - reset at startup
Apply box2d.reset
in bootloader main loop once to reset box2d physics at startup
box2d.reset(r0);
box2d.world - create world
Create world
_ @sys.box2d;
gravity.x 0;
gravity.y 0-1;
b2d.world r15; # need r15 for draw
if (r0) {
b2d.world:=box2d.world(u0, gravity.x, gravity.y);
};
box2d.step - loop step interactions
Step world with velocity and position interactions
velocity.iteractions 8;
position.iteractions 3;
box2d.step(u0, b2d.world, 1/60, velocity.iteractions, position.iteractions);
box2d.shape.create.circle - create body circle
Set options, create body, shape and fixture. Define the collisions
ib0 { _ box2d.default.dynamic.body.info;
x 100;
y 200;
damping.linear 0;
gravity.scale 100;
};
b0 0;
b0:=box2d.body.create2(r0, b2d.world, ib0);
b0s0 0;
b0s0:=box2d.shape.create.circle(u0);
box2d.shape.set.radius(u0, b0s0, 10);
b0f0 0;
box2d.fixture.def(u0, 0.2, 0, 0, 0);
b0f0:=box2d.fixture.create(u0, b0, b0s0);
box2d.fixture.filter.collision(u0, b0f0, 1,2+1, 0);
box2d.world.draw - debug draw
b2d.world r15;
_ @sys.box2d;
box2d.world.draw(u0, b2d.world);