Tap many times and eventually the boxes will start going in each other.
-- Boxes
function setup()
rectMode(CENTER)
boxes={}
ground=physics.body(EDGE, vec2(0, 0), vec2(WIDTH, 0))
rEdge=physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))
lEdge=physics.body(EDGE, vec2(0, 0), vec2(0, HEIGHT))
end
function draw()
background(40, 40, 50)
strokeWidth(5)
for a,b in pairs(boxes) do
pushMatrix()
translate(b.x, b.y)
rotate(b.angle)
rect(0, 0, 100, 100)
popMatrix()
end
end
function createBox(x, y, sizeX, sizeY)
pushMatrix()
translate(x, y)
local p=physics.body(POLYGON, vec2(0-sizeX/2, 0-sizeY/2), vec2(sizeX/2, 0-sizeY/2), vec2(0-sizeX/2, sizeY/2), vec2(sizeX/2, sizeY/2))
p.type=DYNAMIC
p.position=vec2(x, y)
p.fixedRotation=false
popMatrix()
return p
end
function touched(t)
if t.state==BEGAN then
table.insert(boxes, createBox(t.x, t.y, 100, 100))
end
end