local World = require("game.world") local Palette = require("rendering.palette") local Effects = {} local CRACK_DURATION = 2.0 local CRACK_MIN_LINES = 8 local CRACK_MAX_LINES = 12 local crack = nil local function buildCrack(cx, cy) local lines = {} local count = CRACK_MIN_LINES + math.floor(math.random() * (CRACK_MAX_LINES - CRACK_MIN_LINES + 1)) local maxLen = math.max(World.screenW, World.screenH) for i = 1, count do local angle = (i / count) * math.pi * 2 + (math.random() - 0.5) * 0.4 local len = maxLen * (0.6 + math.random() * 0.6) -- Jagged shards: a few jittered segments from the impact point outward local segments = {cx, cy} local steps = 3 for s = 1, steps do local frac = s / steps local jitter = (math.random() - 0.5) * len * 0.12 local perpAngle = angle + math.pi / 2 local px = cx + math.cos(angle) * len * frac + math.cos(perpAngle) * jitter local py = cy + math.sin(angle) * len * frac + math.sin(perpAngle) * jitter table.insert(segments, px) table.insert(segments, py) end table.insert(lines, segments) end return { lines = lines, age = 0 } end function Effects.triggerCrack(cx, cy) cx = cx or World.screenW / 2 cy = cy or (World.radarH + World.viewH / 2) crack = buildCrack(cx, cy) end function Effects.update(dt) if crack then crack.age = crack.age + dt if crack.age >= CRACK_DURATION then crack = nil end end end function Effects.draw() if not crack then return end local p = Palette.get() local fade = 1 - (crack.age / CRACK_DURATION) love.graphics.setColor(p.bright[1], p.bright[2], p.bright[3], fade) love.graphics.setLineWidth(2) for _, poly in ipairs(crack.lines) do love.graphics.line(poly) end end function Effects.clear() crack = nil end return Effects