PicoPicoGameEngine

Quick Links

Source Code

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

e_count=30

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

prevBody = ground
for i=0,e_count-1 do
  shape=b2Shape.polygon(
      {density=20,friction=0.2})
  shape:setAsBox(0.5,0.125)
  local body=world:createBody(
    "dynamic",{-14.5+1.0*i,5.0})
  body:createFixture(shape)

  world:createJoint(
    "revolute",prevBody,body,
    {anchor={x=-15.0+1.0*i,y=5.0}})

  if (i==(e_count / 2)) then
    middle = body
  end

  prevBody = body
end

world:createJoint(
   "revolute",prevBody,ground,
   {anchor={x=-15.0+1.0*e_count,y=5.0}})

for i=0,1 do
  shape=b2Shape.polygon({density=1})
  shape:set({-0.5,0.0,0.5,0.0,0.0,1.5})
  local body=world:createBody(
     "dynamic",{-8.0 + 8.0 * i, 12.0})
  body:createFixture(shape)

end

for i=0,2 do
  shape=b2Shape.circle({density=1})
  shape.radius=0.5
  local body=world:createBody(
     "dynamic",-6.0 + 6.0 * i, 10.0)
  body:createFixture(shape)
end

world:shiftOrigin(-16,30)

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