Source Code
world=b2World.new(0,-10)
world:drawScale(15,-15)
groundBody=world:createBody()
shape=b2Shape.edge()
shape:set(-40,0,40,0)
b1=world:createBody()
b1:createFixture(shape)
shape=b2Shape.polygon()
shape:setAsBox(6,0.25)
body=world:createBody(-1.5,10)
body:createFixture(shape)
shape=b2Shape.polygon(
{density=20,friction=0.1})
shape:setAsBox(0.1,1.0)
for i=0,9 do
body=world:createBody(
"dynamic",-6+1*i,11.25)
body:createFixture(shape)
end
shape=b2Shape.polygon()
shape:setAsBox(7,0.25,{x=0,y=0},0.3)
body=world:createBody(1,6)
body:createFixture(shape)
shape=b2Shape.polygon()
shape:setAsBox(0.25,1.5)
b2=world:createBody(-7,4)
b2:createFixture(shape)
shape=b2Shape.polygon({density=10})
shape:setAsBox(6,0.125)
b3=world:createBody(
"dynamic",-0.9,1,{angle=-0.15})
b3:createFixture(shape)
world:createJoint(
"revolute",b1,b3,
{anchor={-2,1},collideConnected=true})
shape=b2Shape.polygon({density=10})
shape:setAsBox(0.25,0.25)
b4=world:createBody("dynamic",-10,15)
b4:createFixture(shape)
world:createJoint(
"revolute",b2,b4,
{anchor=pppoint(-7,15),
collideConnected=true})
b5=world:createBody("dynamic",6.5,3)
shape=b2Shape.polygon(
{density=10,friction=0.1})
shape:setAsBox(1,0.1,{x=0,y=-0.9},0)
b5:createFixture(shape)
shape=b2Shape.polygon(
{density=10,friction=0.1})
shape:setAsBox(0.1,1,{x=-0.9,y=0},0)
b5:createFixture(shape)
shape=b2Shape.polygon(
{density=10,friction=0.1})
shape:setAsBox(0.1,1,{x= 0.9,y=0},0)
b5:createFixture(shape)
world:createJoint(
"revolute",b1,b5,
{anchor=pppoint(6,2),
collideConnected=true})
shape=b2Shape.polygon({density=30})
shape:setAsBox(1,0.1)
b6=world:createBody("dynamic",6.5,4.1)
b6:createFixture(shape)
world:createJoint(
"revolute",b5,b6,
{anchor=pppoint(7.5,4),
collideConnected=true})
shape=b2Shape.polygon({density=10})
shape:setAsBox(0.1,1)
b7=world:createBody("dynamic",7.4,1)
b7:createFixture(shape)
length=b7:worldPoint(pppoint(0,-1))
-b3:worldPoint(pppoint(6,0))
world:createJoint(
"distance",b3,b7,{
localAnchorA=pppoint(6,0),
localAnchorB=pppoint(0,-1),
length=length:length()
})
for i=0,3 do
shape=b2Shape.circle({density=10})
shape.radius=0.2
body=world:createBody(
"dynamic",5.9 + 2.0 * 0.2 * i, 2.4)
body:createFixture(shape)
end
world:shiftOrigin(-11,20)
function start()
world:debugDrag(pptouch())
world:step()
world:debugDrawBody()
world:debugDrawJoint()
end