This commit is contained in:
2025-12-08 21:31:09 +01:00
parent 2a4cbd4d66
commit 6e2ebdd0da

View File

@@ -3,7 +3,7 @@
-- desc: Life of a programmer in the Vector -- desc: Life of a programmer in the Vector
-- site: http://teletype.hu -- site: http://teletype.hu
-- license: MIT License -- license: MIT License
-- version: 0.4 -- version: 0.5
-- script: lua -- script: lua
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@@ -44,14 +44,16 @@ local Config = {
-- Game States -- Game States
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local GAME_STATE_SPLASH = 0 local GAME_STATE_SPLASH = 0
local GAME_STATE_MENU = 1 local GAME_STATE_INTRO = 1
local GAME_STATE_GAME = 2 local GAME_STATE_MENU = 2
local GAME_STATE_DIALOG = 3 local GAME_STATE_GAME = 3
local GAME_STATE_DIALOG = 4
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Modules -- Modules
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local Splash = {} local Splash = {}
local Intro = {}
local Menu = {} local Menu = {}
local Game = {} local Game = {}
local UI = {} local UI = {}
@@ -65,6 +67,11 @@ local MenuActions = {}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local State = { local State = {
game_state = GAME_STATE_SPLASH, game_state = GAME_STATE_SPLASH,
intro = {
y = Config.screen.height,
speed = 0.5,
text = "Mr. Anderson is an average\nprogrammer. His daily life\nrevolves around debugging,\npull requests, and end-of-sprint\nmeetings, all while secretly\ndreaming of being destined\nfor something more."
},
current_screen = 1, current_screen = 1,
dialog_text = "", dialog_text = "",
splash_timer = Config.timing.splash_duration, splash_timer = Config.timing.splash_duration,
@@ -226,7 +233,36 @@ end
function Splash.update() function Splash.update()
State.splash_timer = State.splash_timer - 1 State.splash_timer = State.splash_timer - 1
if State.splash_timer <= 0 then if State.splash_timer <= 0 or Input.action() then
State.game_state = GAME_STATE_INTRO
end
end
--------------------------------------------------------------------------------
-- Intro Module
--------------------------------------------------------------------------------
function Intro.draw()
cls(Config.colors.black)
local x = (Config.screen.width - 132) / 2 -- Centered text
print(State.intro.text, x, State.intro.y, Config.colors.green)
end
function Intro.update()
State.intro.y = State.intro.y - State.intro.speed
-- Count lines in intro text to determine when scrolling is done
local lines = 1
for _ in string.gmatch(State.intro.text, "\n") do
lines = lines + 1
end
-- When text is off-screen, go to menu
if State.intro.y < -lines * 8 then
State.game_state = GAME_STATE_MENU
end
-- Skip intro by pressing A
if Input.action() then
State.game_state = GAME_STATE_MENU State.game_state = GAME_STATE_MENU
end end
end end
@@ -428,6 +464,10 @@ local STATE_HANDLERS = {
Splash.update() Splash.update()
Splash.draw() Splash.draw()
end, end,
[GAME_STATE_INTRO] = function()
Intro.update()
Intro.draw()
end,
[GAME_STATE_MENU] = function() [GAME_STATE_MENU] = function()
Menu.update() Menu.update()
Menu.draw() Menu.draw()