From ec5c8277a02010867b07d7891dd51cdc8d3fc332 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Tue, 25 Aug 2026 09:00:00 +0200 Subject: [PATCH] feat(light): add light-aware visibility --- src/light.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/light.lua diff --git a/src/light.lua b/src/light.lua new file mode 100644 index 0000000..a8a4a60 --- /dev/null +++ b/src/light.lua @@ -0,0 +1,25 @@ +-- Visibility with light. The player sees out to their carried light radius via +-- shadowcasting; on top of that, any static emitter the player can already see +-- casts its own pool of light, so a lit room reveals itself the moment the +-- player glimpses its brazier. Darkness is simply a smaller player radius. + +local Fov = require("fov") + +local Light = {} + +function Light.compute(map, originX, originY, radius, lights) + local visible = Fov.compute(map, originX, originY, radius) + if lights then + for _, emitter in ipairs(lights) do + if visible[map:index(emitter.x, emitter.y)] then + local pool = Fov.compute(map, emitter.x, emitter.y, emitter.radius) + for idx in pairs(pool) do + visible[idx] = true + end + end + end + end + return visible +end + +return Light