PicoPicoGameEngine

Quick Links

Source Code

world=b2World.new(0,10)
groundBody=world:createBody(0,0)

shape=b2Shape.edge()
shape:set(-40,0,40,0)
ground=world:createBody(0,0)
ground:createFixture(shape)

shape=b2Shape.polygon({density=5})
shape:setAsBox(0.5,0.5)
body0=world:createBody("dynamic",-5,5)
body0:createFixture(shape)
body1=world:createBody("dynamic", 5,5)
body1:createFixture(shape)
body2=world:createBody("dynamic", 5,15)
body2:createFixture(shape)
body3=world:createBody("dynamic",-5,15)
body3:createFixture(shape)

bodyA=ground
bodyB=body0
localAnchorA=pppoint(-10,0)
localAnchorB=pppoint(-0.5,-0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=ground
bodyB=body1
localAnchorA=pppoint(10,0)
localAnchorB=pppoint(0.5,-0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=ground
bodyB=body2
localAnchorA=pppoint(10,20)
localAnchorB=pppoint(0.5,0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=ground
bodyB=body3
localAnchorA=pppoint(-10,20)
localAnchorB=pppoint(-0.5,0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=body0
bodyB=body1
localAnchorA=pppoint(0.5,0)
localAnchorB=pppoint(-0.5,0)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=body1
bodyB=body2
localAnchorA=pppoint(0,0.5)
localAnchorB=pppoint(0,-0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=body2
bodyB=body3
localAnchorA=pppoint(-0.5,0)
localAnchorB=pppoint(0.5,0)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

bodyA=body3
bodyB=body0
localAnchorA=pppoint(0,-0.5)
localAnchorB=pppoint(0,0.5)
p1=bodyA:worldPoint(localAnchorA)
p2=bodyB:worldPoint(localAnchorB)
d=p2-p1
world:createJoint("distance",
  bodyA,bodyB,
  {
  localAnchorA=localAnchorA,
  localAnchorB=localAnchorB,
  frequencyHz=2.0,
  dampingRatio=0.0,
  length=d:length()
  })

world:shiftOrigin(-16,-15)

function start()
  world:debugDrag(pptouch())
  world:step()
  world:debugDrawBody()
  world:debugDrawJoint()
end