local mqtt = require("mqtt_library") function mqttcb(topic, message) print("Received: " .. topic .. ": " .. message) end function blip (vel) local x, y = 0, 0 local width, height = love.graphics.getDimensions( ) return { update = coroutine.wrap (function () while true do x = x+vel/10 if x > width then x = 0 end coroutine.yield() end return true end), affected = function (pos) if pos>x and pos width then x = 0 end end, draw = function () love.graphics.rectangle("line", x, y, 30, 10) end } end function love.keypressed(key) if key == 'a' then mqtt_client:publish("log", "atirou") pos = jog.try() for i in ipairs(listabls) do local hit = listabls[i].affected(pos) if hit then table.remove(listabls, i) end end end end function love.load() mqtt_client = mqtt.client.create("127.0.0.1", 1883, mqttcb) mqtt_client:connect("cliente love") mqtt_client:subscribe({"controle"}) jog = jogador() listabls = {} for i = 1, 5 do listabls[i] = blip(i) end end function love.draw() jog.draw() for i = 1,#listabls do listabls[i].draw() end end function love.update(dt) mqtt_client:handler() jog.update(dt) for i = 1,#listabls do listabls[i].update() end end