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,10)
ground:createFixture(shape)

local N=15
y=-5

prevBody=ground
for i=0,N-1 do
  if (i==N-1) then
    shape=b2Shape.polygon({
      density=100,
      frictoin=0.2,
      categoryBits=0x0002,
      maskBits=0xfffd})
    shape:setAsBox(1.5,1.5)
    body=world:createBody(
      "dynamic",
      1.0 * i, y,
      {angularDamping=0.4})
    body:createFixture(shape)
    world:createJoint(
      "revolute",
      prevBody,body,
      {anchor=pppoint(i,y),
       collideConnected=false
      })
  else
    shape=b2Shape.polygon({
      density=20,
      frictoin=0.2,
      categoryBits=0x0001,
      maskBits=0xfffd})
    shape:setAsBox(0.5,0.125)
    body=world:createBody(
      "dynamic",
      0.5+1*i,y)
    body:createFixture(shape)
    world:createJoint(
      "revolute",
      prevBody,body,
      {anchor=pppoint(i,y),
       collideConnected=false
      })
  end
  prevBody=body
end

extraLength=0.01
world:createJoint(
  "rope",
  ground,prevBody,
  {
  maxLength = N-1.0+extraLength,
  localAnchorA=pppoint(0,-10+y),
  localAnchorB=pppoint(0,0),
  })

world:shiftOrigin(-16,-15)

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