Code: Select all
Block = {}
Block.__index = Block
function Block.new(x, y, r, g, b )
local instance = setmetatable({}, Block)
instance.x = x
instance.y = y
instance.width = 50
instance.height = 50
instance.r = r
instance.g = g
instance.b = b
instance.body = love.physics.newBody(world, instance.x, instance.y, "static")
instance.shape = love.physics.newRectangleShape(instance.width, instance.height)
instance.fixture =love.physics.newFixture(instance.body, instance.shape)
return instance
end
function Block:draw()
love.graphics.rectangle("fill", self.x - self.width / 2, self.y - self.height / 2, self.width, self.height)
end
Code: Select all
Blocks = {0, 0, 1, 1, 1, 0}
for i, block in ipairs(Blocks) do
Block.new(--some magic involving i)
end