DX: textos a taula configurable, sentence case i tecla Q per sortir partida

This commit is contained in:
2026-05-15 13:52:26 +02:00
parent 4d7868de49
commit cd319a3bec
2 changed files with 64 additions and 12 deletions
+18
View File
@@ -60,3 +60,21 @@ skin = "native"
-- keys.right = KEY_RIGHT -- keys.right = KEY_RIGHT
-- keys.dig_left = KEY_Z -- keys.dig_left = KEY_Z
-- keys.dig_right = KEY_X -- keys.dig_right = KEY_X
-- keys.quit = KEY_Q -- abandona la partida → game over
-- ====================================================================
-- TEXTOS DEL JOC
-- ====================================================================
-- Tots els missatges que veu el jugador. Pots editar per a corregir
-- ortografia o traduir a una altra variant sense haver de tocar el .lua.
-- (Convencio: Inicial Majuscula, resta minuscula.)
-- textos.title_press_play = "Prem l'espai per a jugar"
-- textos.game_over = "Fi de joc"
-- textos.new_record = "Nou record !"
-- textos.score_label = "Punts"
-- textos.level_label = "Nivell"
-- textos.lives_label = "Vides"
-- textos.record_label = "Record"
-- textos.name_label = "Nom:"
-- textos.name_help = "(A-Z)"
+46 -12
View File
@@ -49,6 +49,8 @@ SKINS = {
glif = SKINS.custom -- s'actualitza a init() segons la config glif = SKINS.custom -- s'actualitza a init() segons la config
-- Tecles del joc — sobreescriuibles per config.lua. -- Tecles del joc — sobreescriuibles per config.lua.
-- Nota: KEY_ESCAPE no es pot usar perque el interpret ascii la captura
-- per a la seva consola de debug abans que Lua la veja.
keys = { keys = {
up = KEY_UP, up = KEY_UP,
down = KEY_DOWN, down = KEY_DOWN,
@@ -56,6 +58,7 @@ keys = {
right = KEY_RIGHT, right = KEY_RIGHT,
dig_left = KEY_Z, dig_left = KEY_Z,
dig_right = KEY_X, dig_right = KEY_X,
quit = KEY_Q, -- abandona la partida → game over
} }
-- Paleta — tots els colors son sobreescriuibles per config.lua. -- Paleta — tots els colors son sobreescriuibles per config.lua.
@@ -77,6 +80,20 @@ colors = {
title = COLOR_LIGHT_RED, title = COLOR_LIGHT_RED,
} }
-- Textos del joc — sobreescriuibles per config.lua (taula `textos`).
-- Tots en sentence case (Inicial Majuscula, resta minuscula).
textos = {
title_press_play = "Prem l'espai per a jugar",
game_over = "Fi de joc",
new_record = "Nou record !",
score_label = "Punts", -- HUD i pantalla de nou record
level_label = "Nivell",
lives_label = "Vides",
record_label = "Record",
name_label = "Nom:",
name_help = "(A-Z)",
}
-- Estats (de TIPOS.PAS — son bitflags per a SelectEstat dels enemics) -- Estats (de TIPOS.PAS — son bitflags per a SelectEstat dels enemics)
NORMAL = 0 NORMAL = 0
PUJAR = 0x01 PUJAR = 0x01
@@ -395,10 +412,11 @@ function update_title()
neteja_fons() neteja_fons()
pintar_mapa(1) -- desplacem +1 col per a centrar el logo de map 0 pintar_mapa(1) -- desplacem +1 col per a centrar el logo de map 0
-- Missatge parpadejant ("Prem l'espai per a jugar") -- Missatge parpadejant (textos.title_press_play)
if flr(cnt() / 30) % 2 == 0 then if flr(cnt() / 30) % 2 == 0 then
color(COLOR_WHITE, colors.bg) color(COLOR_WHITE, colors.bg)
print("PREM L'ESPAI PER A JUGAR", 8, 22) local t = textos.title_press_play
print(t, flr((40 - strlen(t)) / 2), 22)
end end
pintar_hud() pintar_hud()
@@ -413,7 +431,8 @@ function update_gameover()
pintar_pepe() pintar_pepe()
color(colors.title, colors.bg) color(colors.title, colors.bg)
print("F I D E J O C", 11, 12) local g = textos.game_over
print(g, flr((40 - strlen(g)) / 2), 12)
pintar_hud() pintar_hud()
@@ -435,12 +454,15 @@ end
function update_entername() function update_entername()
neteja_fons() neteja_fons()
color(colors.title, colors.bg) color(colors.title, colors.bg)
print("NOU RECORD !", 14, 10) local t = textos.new_record
print(t, flr((40 - strlen(t)) / 2), 10)
color(colors.diners, colors.bg) color(colors.diners, colors.bg)
print("PUNTS "..string.format("%03d", hi_score), 15, 12) local s = textos.score_label.." "..string.format("%03d", hi_score)
print(s, flr((40 - strlen(s)) / 2), 12)
color(COLOR_WHITE, colors.bg) color(COLOR_WHITE, colors.bg)
print("NOM: "..nom_hi_score, 16, 15) local n = textos.name_label.." "..nom_hi_score
print("(A-Z)", 17, 17) print(n, flr((40 - strlen(n)) / 2), 15)
print(textos.name_help, flr((40 - strlen(textos.name_help)) / 2), 17)
pintar_hud() pintar_hud()
@@ -460,6 +482,13 @@ end
-- ----- PLAYING ----- -- ----- PLAYING -----
function update_playing() function update_playing()
-- Abandonar partida → flux de game over (como en el RUNNER.PAS amb ESC)
if btnp(keys.quit) then
sfx_gameover()
set_estat(ESTAT_GAMEOVER)
return
end
-- Cavar es immediat (un sol forat per pulsacio) -- Cavar es immediat (un sol forat per pulsacio)
if pepe.estat == NORMAL then if pepe.estat == NORMAL then
if btnp(keys.dig_left) and pot_cavar(-1) then foradar(pepe.x-1, pepe.y+1); sfx_dig() end if btnp(keys.dig_left) and pot_cavar(-1) then foradar(pepe.x-1, pepe.y+1); sfx_dig() end
@@ -714,10 +743,11 @@ function pintar_hud()
end end
-- Text dins del marc -- Text dins del marc
print("NIVELL "..string.format("%02d", level), 3, 26) print(textos.level_label.." "..string.format("%02d", level), 3, 26)
print("PUNTS "..string.format("%03d", score), 16, 26) print(textos.score_label.." "..string.format("%03d", score), 16, 26)
print("VIDES "..tostr(pepe.vides), 29, 26) print(textos.lives_label.." "..tostr(pepe.vides), 29, 26)
print("RECORD "..string.format("%03d", hi_score).." "..nom_hi_score, 13, 28) local r = textos.record_label.." "..string.format("%03d", hi_score).." "..nom_hi_score
print(r, flr((40 - strlen(r)) / 2), 28)
end end
-- Carrega config.lua si existeix. Si falta o te errors, queden els defaults. -- Carrega config.lua si existeix. Si falta o te errors, queden els defaults.
@@ -725,9 +755,10 @@ end
-- camp a camp, hi haura claus que falten. Fem un merge amb les defaults -- camp a camp, hi haura claus que falten. Fem un merge amb les defaults
-- guardades per a que no quede res a nil. -- guardades per a que no quede res a nil.
function carregar_config() function carregar_config()
local saved_colors, saved_keys = {}, {} local saved_colors, saved_keys, saved_textos = {}, {}, {}
for k, v in pairs(colors) do saved_colors[k] = v end for k, v in pairs(colors) do saved_colors[k] = v end
for k, v in pairs(keys) do saved_keys[k] = v end for k, v in pairs(keys) do saved_keys[k] = v end
for k, v in pairs(textos) do saved_textos[k] = v end
pcall(dofile, "config.lua") pcall(dofile, "config.lua")
for k, v in pairs(saved_colors) do for k, v in pairs(saved_colors) do
if colors[k] == nil then colors[k] = v end if colors[k] == nil then colors[k] = v end
@@ -735,6 +766,9 @@ function carregar_config()
for k, v in pairs(saved_keys) do for k, v in pairs(saved_keys) do
if keys[k] == nil then keys[k] = v end if keys[k] == nil then keys[k] = v end
end end
for k, v in pairs(saved_textos) do
if textos[k] == nil then textos[k] = v end
end
end end
function init() function init()