Estructura DX i escena logo JAILGAMES animada
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
-- Escena 'titol' — menu principal.
|
||||
--
|
||||
-- Tot esta basat en delta time: parpelleig de cursor, animacio del
|
||||
-- subtitol, etc. La llista d'opcions es extensible: nomes cal afegir
|
||||
-- una entrada amb un text i una funcio.
|
||||
|
||||
local M = {}
|
||||
|
||||
local TITOL = "PEPE EL PINTOR DX"
|
||||
local SUBTITOL = "port lliure de PINTOR3 (Sergi Valor, 1999)"
|
||||
local PERIODE_CURSOR = 0.35
|
||||
|
||||
local manager, input
|
||||
local temps = 0
|
||||
local cursor = 1
|
||||
local opcions = {}
|
||||
|
||||
local function fes_opcions()
|
||||
opcions = {
|
||||
{
|
||||
text = "COMENCAR PARTIDA",
|
||||
accio = function() manager.canvia("joc") end,
|
||||
},
|
||||
-- A futur: CONTROLS, CREDITS, OPCIONS, EIXIR...
|
||||
}
|
||||
end
|
||||
|
||||
function M.entra(servicis, _args)
|
||||
manager = servicis.manager
|
||||
input = servicis.input
|
||||
temps = 0
|
||||
cursor = 1
|
||||
fes_opcions()
|
||||
end
|
||||
|
||||
function M.update(dt)
|
||||
temps = temps + dt
|
||||
|
||||
if input.acaba_premuda("amunt") then
|
||||
cursor = cursor - 1
|
||||
if cursor < 1 then cursor = #opcions end
|
||||
end
|
||||
if input.acaba_premuda("avall") then
|
||||
cursor = cursor + 1
|
||||
if cursor > #opcions then cursor = 1 end
|
||||
end
|
||||
if input.acaba_premuda("accept") then
|
||||
local op = opcions[cursor]
|
||||
if op and op.accio then op.accio() end
|
||||
end
|
||||
end
|
||||
|
||||
local function centra(text, y, ink, paper)
|
||||
local x = math.floor((40 - #text) / 2)
|
||||
color(ink, paper)
|
||||
print(text, x, y)
|
||||
end
|
||||
|
||||
function M.draw()
|
||||
color(COLOR_WHITE, COLOR_BLACK)
|
||||
cls()
|
||||
|
||||
-- Marc decoratiu — barres horitzontals de pintura.
|
||||
color(COLOR_LIGHT_RED, COLOR_BLACK)
|
||||
print(string.rep(chr(220), 40), 0, 1)
|
||||
print(string.rep(chr(223), 40), 0, 27)
|
||||
|
||||
centra(TITOL, 6, COLOR_YELLOW, COLOR_BLACK)
|
||||
centra(SUBTITOL, 8, COLOR_LIGHT_GRAY, COLOR_BLACK)
|
||||
|
||||
-- Menu d'opcions
|
||||
local y0 = 14
|
||||
for i, op in ipairs(opcions) do
|
||||
local actiu = (i == cursor)
|
||||
local visible_cursor = math.floor(temps / PERIODE_CURSOR) % 2 == 0
|
||||
local marca = (actiu and visible_cursor) and chr(16) or " "
|
||||
local text = marca .. " " .. op.text
|
||||
local ink = actiu and COLOR_LIGHT_GREEN or COLOR_LIGHT_GRAY
|
||||
centra(text, y0 + (i - 1) * 2, ink, COLOR_BLACK)
|
||||
end
|
||||
|
||||
centra("amunt/avall + enter", 24, COLOR_DARK_GRAY, COLOR_BLACK)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user