--- @section MysteriousManScreen local STATE_TEXT = "text" local STATE_DAY = "day" local STATE_CHOICE = "choice" local ASC_01_TEXT = [[ Normann seems to be in line, ... and stays seeking for oxes ... within the confines. ... Very good. ]] local ASC_12_TEXT = [[ We have a problem! ... Normann formed his first thought. ... He saw the tracks. ]] local ASC_23_TEXT = [[ Not good, not terrible. ... Normann caught his glimpse ... of another way ... - quite literally - ... if this continues, ... we will lose control. ]] local ASC_34_TEXT = [[ There is no turning back now for Norman. ... He caught on. ... I hoped it would never come to this... ]] --[[ Norman speaks for the first time during MM screen ]] local ASC_45_TEXT = [[ Wait, who are you? ... *silence* ... Why am I seeing this? ... *silence* ... ]] local ascension_texts = { [1] = ASC_01_TEXT, [2] = ASC_12_TEXT, [3] = ASC_23_TEXT, [4] = ASC_34_TEXT, [5] = ASC_45_TEXT, } function MysteriousManScreen.get_text_for_level(level) return ascension_texts[level] or ASC_01_TEXT end local state = STATE_TEXT local text_y = Config.screen.height local text_speed = 12 -- pixels per second local day_timer = 0 local day_display_seconds = 2 local text_done = false local text_done_timer = 0 local TEXT_DONE_HOLD_SECONDS = 2 local selected_choice = 1 local text = ASC_01_TEXT local day_text_override = nil local on_text_complete = nil local show_mysterious_screen = true local trigger_flash_on_wake = false MysteriousManScreen.choices = { { label = "Wake Up", }, { label = "Stay in Bed", }, } -- Draws the background image -- @within MysteriousManScreen function MysteriousManScreen.draw_background() RLE.draw("mysterious_man_background") end function MysteriousManScreen.draw_day_switch_background() RLE.draw("day_switch_background") end -- Transitions from the text phase to the day display phase, starting the timer for how long the day label is shown. -- @within MysteriousManScreen function MysteriousManScreen.go_to_day_state() if on_text_complete then on_text_complete() on_text_complete = nil end if Context.game.current_screen ~= "mysterious_man" then return end state = STATE_DAY day_timer = day_display_seconds end -- Norman chooses to wake up, starting the button mash minigame and flash, then going to the next day. -- @within MysteriousManScreen function MysteriousManScreen.wake_up() Context.home_norman_visible = false Util.go_to_screen_by_id("home") MinigameButtonMashWindow.start("game", { focus_center_x = (Config.screen.width / 2) - 22, focus_center_y = (Config.screen.height / 2) - 18, focus_initial_radius = 0, target_points = 100, instruction_text = "Wake up Norman!", show_progress_text = false, on_win = function() Audio.music_play_wakingup() Meter.show() if trigger_flash_on_wake then trigger_flash_on_wake = false Ascension.start_flash() end Window.set_current("game") end, }) end -- Norman chooses to stay in bed, skipping the minigame and flash, and going straight to the next day. -- @within MysteriousManScreen function MysteriousManScreen.stay_in_bed() Day.increase() state = STATE_DAY day_timer = day_display_seconds end --- Starts the mysterious man screen. --- @param[opt] options table Optional configuration.
--- Fields:
--- * text (string) Override for the scrolling text.
--- * day_text (string) Override for the centered day label.
--- * on_text_complete (function) Callback fired once when the text phase ends.
--- * skip_text (boolean) If true, skip the text phase and go straight to day display.
function MysteriousManScreen.start(options) options = options or {} day_timer = 0 text_done = false text_done_timer = 0 selected_choice = 1 text = options.text or ASC_01_TEXT text_y = Config.screen.height day_text_override = options.day_text on_text_complete = options.on_text_complete Meter.hide() trigger_flash_on_wake = not options.skip_text if options.skip_text then show_mysterious_screen = false state = STATE_DAY day_timer = day_display_seconds else show_mysterious_screen = true state = STATE_TEXT end Util.go_to_screen_by_id("mysterious_man") Window.set_current("game") end --- Sets the scrolling text content. --- @param new_text string The text to display. function MysteriousManScreen.set_text(new_text) text = new_text end Screen.register({ id = "mysterious_man", name = "Mysterious Man", decisions = {}, background_color = Config.colors.black, init = function() Audio.music_play_mystery() end, exit = function() Audio.music_stop() end, update = function() if state == STATE_TEXT then if not text_done then text_y = text_y - (text_speed * Context.delta_time) local lines = 1 for _ in string.gmatch(text, "\n") do lines = lines + 1 end if text_y < -lines * 8 or Input.select() then text_done = true text_done_timer = TEXT_DONE_HOLD_SECONDS -- If skipped by user, go to day state immediately if Input.select() then MysteriousManScreen.go_to_day_state() end end else text_done_timer = text_done_timer - Context.delta_time if text_done_timer <= 0 or Input.select() then MysteriousManScreen.go_to_day_state() -- to be continued if 4 <= Ascension.get_level() then Window.set_current("continued") end end end elseif state == STATE_DAY then day_timer = day_timer - Context.delta_time if day_timer <= 0 or Input.select() then if trigger_flash_on_wake or Ascension.get_level() < 1 then MysteriousManScreen.wake_up() else state = STATE_CHOICE selected_choice = 1 end end elseif state == STATE_CHOICE then selected_choice = UI.update_menu(MysteriousManScreen.choices, selected_choice) if Input.select() then Audio.sfx_select() if selected_choice == 1 then MysteriousManScreen.wake_up() else MysteriousManScreen.stay_in_bed() end end end end, draw = function() if show_mysterious_screen then MysteriousManScreen.draw_background() end if state == STATE_TEXT then local cx = Config.screen.width / 2 local line_y = text_y for line in (text .. "\n"):gmatch("(.-)\n") do Print.text_center(line, cx, line_y, Config.colors.light_grey) line_y = line_y + 8 end elseif state == STATE_DAY then MysteriousManScreen.draw_day_switch_background() local day_text = day_text_override or ("Day " .. Context.day_count) Print.text_center( day_text, Config.screen.width / 2, Config.screen.height / 2 - 3, Config.colors.white ) elseif state == STATE_CHOICE then local menu_x = (Config.screen.width - 60) / 2 local menu_y = (Config.screen.height - 20) / 2 UI.draw_menu(MysteriousManScreen.choices, selected_choice, menu_x, menu_y) end end, })