From 3bb1fb7941da47287629491c8f32325471c9a5c6 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Thu, 12 Mar 2026 00:54:09 +0100 Subject: [PATCH] glitch --- impostor.inc | 1 + inc/decision/decision.go_to_office.lua | 1 + inc/init/init.context.lua | 5 +++ inc/logic/logic.glitch.lua | 57 ++++++++++++++++++++++++++ inc/system/system.main.lua | 1 + 5 files changed, 65 insertions(+) create mode 100644 inc/logic/logic.glitch.lua diff --git a/impostor.inc b/impostor.inc index d3e0332..75b404a 100644 --- a/impostor.inc +++ b/impostor.inc @@ -11,6 +11,7 @@ logic/logic.day.lua logic/logic.timer.lua logic/logic.trigger.lua logic/logic.minigame.lua +logic/logic.glitch.lua system/system.ui.lua audio/audio.manager.lua audio/audio.songs.lua diff --git a/inc/decision/decision.go_to_office.lua b/inc/decision/decision.go_to_office.lua index 4cd3f2d..e6285f3 100644 --- a/inc/decision/decision.go_to_office.lua +++ b/inc/decision/decision.go_to_office.lua @@ -2,6 +2,7 @@ Decision.register({ id = "go_to_office", label = "Go to Office", handle = function() + Glitch.show() Util.go_to_screen_by_id("office") end, }) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index e282b50..dac01ff 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -42,6 +42,11 @@ function Context.initial_data() current_situation = nil, }, day_count = 1, + glitch = { + enabled = false, + state = "active", + timer = 0, + }, _end = { state = "choice", selection = 1, diff --git a/inc/logic/logic.glitch.lua b/inc/logic/logic.glitch.lua new file mode 100644 index 0000000..2d277d9 --- /dev/null +++ b/inc/logic/logic.glitch.lua @@ -0,0 +1,57 @@ +Glitch = {} + +--- Shows the glitch effect. +--- @within Glitch +function Glitch.show() + if Context and Context.glitch then + Context.glitch.enabled = true + end +end + +--- Hides the glitch effect. +--- @within Glitch +function Glitch.hide() + if Context and Context.glitch then + Context.glitch.enabled = false + end +end + +--- Draws the glitch effect if active. +--- @within Glitch +function Glitch.draw() + if not Context or not Context.glitch or not Context.glitch.enabled then return end + + -- Update state timer + Context.glitch.timer = Context.glitch.timer - 1 + if Context.glitch.timer <= 0 then + if Context.glitch.state == "active" then + Context.glitch.state = "waiting" + Context.glitch.timer = math.random(20, 60) -- Time to stay fixed + else + Context.glitch.state = "active" + Context.glitch.timer = math.random(40, 100) -- Time to stay glitchy + end + end + + -- Draw stripes only when active + if Context.glitch.state == "active" then + for i = 1, 15 do + local rx = math.random(0, Config.screen.width - 1) + local ry = math.random(0, Config.screen.height - 1) + + -- Sample color at the random point + local color = pix(rx, ry) + + -- Determine random length for the stripe (2-40) + local length = math.random(2, 40) + + -- Draw the vertical stripe + for sy = 0, length - 1 do + local dy = ry + sy + if dy < Config.screen.height then + pix(rx, dy, color) + end + end + end + end +end diff --git a/inc/system/system.main.lua b/inc/system/system.main.lua index 9140532..7522b1e 100644 --- a/inc/system/system.main.lua +++ b/inc/system/system.main.lua @@ -27,5 +27,6 @@ function TIC() if Context.game_in_progress then Meter.draw() Timer.draw() + Glitch.draw() end end