Code: Select all
function load()
world = love.physics.newWorld(2000, 2000)
world:setGravity(0, 5.0)
ground = love.physics.newBody(world, 0, 0, 0)
ground_shape = love.physics.newRectangleShape(ground, 400, 500, 600, 10)
blocks = {bodies = {}, shapes = {}}
end
function update(dt)
dt = dt * 10
world:update(dt)
end
function draw()
love.graphics.polygon(love.draw_line, ground_shape:getPoints())
for i=1,#blocks.shapes do
love.graphics.polygon(0, blocks.shapes[i]:getPoints())
end
end
function block_new(x, y)
local body = love.physics.newBody(world, x, y)
local shape = love.physics.newRectangleShape(body, x, y, 50, 50)
body:setMassFromShapes()
table.insert(blocks.bodies, body)
table.insert(blocks.shapes, shape)
end
function mousepressed(x, y, button)
block_new(x, y)
end