local clicks = {}

clicks.feedback = {}
clicks.feedback.time = 0.25
clicks.feedback.color = {red = 0xff, green = 0xff, blue = 0xff}

function clicks:add(x, y)
    table.insert(self, {x = x, y = y, time = self.feedback.time})
end

function clicks:update(dt)
    local condemned = {}

    for i, c in ipairs(self) do
        c.time = c.time - dt
        if c.time < 0 then
            table.insert(condemned, i)
        end
    end

    for _, i in ipairs(condemned) do
        table.remove(self, i)
    end
end

function clicks:draw()
    for _, c in ipairs(self) do
        local alpha = c.time / self.feedback.time
        local radius = (1 - alpha) * 15 + 5
        love.graphics.setColor(self.feedback.color.red, self.feedback.color.green, self.feedback.color.blue, alpha * 0xff)
        love.graphics.circle("fill", c.x, c.y, radius)
    end
end

return clicks
