local shrines = {}

shrines.time = 0

function shrines:add(x, y)
    table.insert(self, {
        x = x;
        y = y;
        radius = 100;
        progress = 0;
        strength = 100;
        near_player = false;
    })
end

function shrines:update(dt)
    self.time = self.time + dt

    for _, shrine in ipairs(self) do
        if shrine.active then
            shrine.progress = shrine.progress + (shrine.strength - shrine.progress) * dt;

        else
            shrine.progress = shrine.progress + (0 - shrine.progress) * dt
        end
    end
end

function shrines:detect_player(player)
    for _, shrine in ipairs(self) do
        local dx = shrine.x - player.position.x
        local dy = shrine.y - player.position.y
        local distance = math.sqrt(dx ^ 2 + dy ^ 2)
        if distance < shrine.radius then
            shrine.active = true

        else
            shrine.active = false
        end
    end
end

function shrines:draw()
    for _, shrine in ipairs(self) do
        love.graphics.push()
        love.graphics.translate(shrine.x, shrine.y)

        love.graphics.setColor(0xff * (shrine.progress / shrine.strength) * (math.cos(self.time) + 1) / 2, 0xff * (shrine.progress / shrine.strength) * (math.sin(self.time) + 1) / 2, 0x00)
        love.graphics.circle("fill", 0, 0, 50)

        love.graphics.pop()
    end
end

return shrines
