DX: paleta configurable i fons unificat darrere dels glifs

This commit is contained in:
2026-05-15 13:19:22 +02:00
parent 8291f386fa
commit e34b5a20ce
2 changed files with 92 additions and 39 deletions
+26
View File
@@ -20,3 +20,29 @@
-- (En els dos casos el char 0 es reescriu a zeros, perque el ROM d'ascii -- (En els dos casos el char 0 es reescriu a zeros, perque el ROM d'ascii
-- hi te una caixa hueca que taparia tot el mapa.) -- hi te una caixa hueca que taparia tot el mapa.)
skin = "native" skin = "native"
-- ====================================================================
-- PALETA DE COLORS
-- ====================================================================
-- Constants disponibles:
-- COLOR_BLACK=0 COLOR_BLUE=1 COLOR_GREEN=2 COLOR_CYAN=3
-- COLOR_RED=4 COLOR_MAGENTA=5 COLOR_BROWN=6 COLOR_LIGHT_GRAY=7
-- COLOR_DARK_GRAY=8 COLOR_LIGHT_BLUE=9 COLOR_LIGHT_GREEN=10
-- COLOR_LIGHT_CYAN=11 COLOR_LIGHT_RED=12 COLOR_LIGHT_MAGENTA=13
-- COLOR_YELLOW=14 COLOR_WHITE=15
--
-- Pots sobreescriure nomes les que vulgues. Comenta una linia
-- per a deixar el valor per defecte.
-- colors.bg = COLOR_BLUE -- fons del nivell
-- colors.pedra = COLOR_BROWN -- murs i blocs degradats
-- colors.diners = COLOR_YELLOW -- $ monedes
-- colors.escala = COLOR_LIGHT_CYAN -- ═ escales
-- colors.corda = COLOR_LIGHT_GRAY -- ─ cordes
-- colors.pepe = COLOR_WHITE -- el protagonista
-- colors.malo = COLOR_LIGHT_RED -- enemics
-- colors.malo_carrega = COLOR_LIGHT_MAGENTA -- enemic portant diners
-- colors.hud_text = COLOR_WHITE -- text del rotul inferior
-- colors.hud_bg = COLOR_BLACK -- fons del rotul inferior
-- colors.border = COLOR_BLUE -- vora exterior de la finestra
-- colors.title = COLOR_LIGHT_RED -- GAME OVER / NOU RECORD
+66 -39
View File
@@ -39,12 +39,24 @@ SKINS = {
} }
glif = SKINS.custom -- s'actualitza a init() segons la config glif = SKINS.custom -- s'actualitza a init() segons la config
-- Colors (de TIPOS.PAS, paleta CGA — coincideix amb la d'ascii) -- Paleta — tots els colors son sobreescriuibles per config.lua.
COL_PEDRA = COLOR_BROWN -- 6 -- bg es el color del fons del nivell (pintat tant a les cel·les buides com
COL_DINERS = COLOR_YELLOW -- 14 -- darrere de cada glif), per a que tot quede integrat en lloc de tindre
COL_ESCALA = COLOR_LIGHT_GRAY -- 7 -- negre darrere dels caracters.
COL_CORDA = COLOR_LIGHT_GRAY -- 7 colors = {
COL_BUIT = COLOR_BLACK -- 0 bg = COLOR_BLUE, -- fons del nivell
pedra = COLOR_BROWN,
diners = COLOR_YELLOW,
escala = COLOR_LIGHT_CYAN,
corda = COLOR_LIGHT_GRAY,
pepe = COLOR_WHITE,
malo = COLOR_LIGHT_RED,
malo_carrega = COLOR_LIGHT_MAGENTA, -- enemic portant diners
hud_text = COLOR_WHITE,
hud_bg = COLOR_BLACK,
border = COLOR_BLUE,
title = COLOR_LIGHT_RED,
}
-- 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
@@ -74,7 +86,7 @@ ESTAT_ENTERNAME = "entername"
-- Estat global -- Estat global
mapa = {} -- mapa[x][y] = { tipo=, color=, temps= } mapa = {} -- mapa[x][y] = { tipo=, color=, temps= }
level = 1 level = 1
pepe = { x=19, y=23, dibuix=PEPE_C, color=COLOR_WHITE, vides=VIDES_INI, estat=NORMAL } pepe = { x=19, y=23, dibuix=PEPE_C, color=colors.pepe, vides=VIDES_INI, estat=NORMAL }
malos = {} malos = {}
score = 0 score = 0
diners_pantalla = 0 diners_pantalla = 0
@@ -114,12 +126,19 @@ function sfx_malo_die() play("l0o3ao4c") end
function sfx_level() play("l1o4ceg") end function sfx_level() play("l1o4ceg") end
function sfx_gameover() play("l1o3bal0gfedco2c") end function sfx_gameover() play("l1o3bal0gfedco2c") end
-- Neteja la pantalla amb el color de fons configurat (en lloc de negre).
function neteja_fons()
color(colors.bg, colors.bg)
cls()
end
function color_de(tipo) function color_de(tipo)
if tipo == PEDRA then return COL_PEDRA end if tipo == PEDRA then return colors.pedra end
if tipo == DINERS then return COL_DINERS end if tipo == DINERS then return colors.diners end
if tipo == ESCALA then return COL_ESCALA end if tipo == ESCALA then return colors.escala end
if tipo == CORDA then return COL_CORDA end if tipo == CORDA then return colors.corda end
return COL_BUIT if tipo == BLOC1 or tipo == BLOC2 or tipo == BLOC3 then return colors.pedra end
return colors.bg
end end
-- Helper segur per llegir el tipus d'una cel·la (fora de mapa = pedra virtual) -- Helper segur per llegir el tipus d'una cel·la (fora de mapa = pedra virtual)
@@ -146,7 +165,7 @@ function pintar_mapa()
for y = 0, MAP_H-1 do for y = 0, MAP_H-1 do
local c = mapa[x][y] local c = mapa[x][y]
if c.tipo ~= BUIT then if c.tipo ~= BUIT then
color(c.color, COL_BUIT) color(c.color, colors.bg)
print(chr(glif[c.tipo]), x, y) print(chr(glif[c.tipo]), x, y)
end end
end end
@@ -154,7 +173,7 @@ function pintar_mapa()
end end
function pintar_pepe() function pintar_pepe()
color(pepe.color, COL_BUIT) color(pepe.color, colors.bg)
print(chr(glif[pepe.dibuix]), pepe.x, pepe.y) print(chr(glif[pepe.dibuix]), pepe.x, pepe.y)
end end
@@ -337,12 +356,12 @@ function update_title()
return return
end end
cls() neteja_fons()
pintar_mapa() pintar_mapa()
-- "PRESS SPACE TO PLAY" parpadejant -- "PRESS SPACE TO PLAY" parpadejant
if flr(cnt() / 30) % 2 == 0 then if flr(cnt() / 30) % 2 == 0 then
color(COLOR_WHITE, COLOR_BLACK) color(COLOR_WHITE, colors.bg)
print("PRESS SPACE TO PLAY", 10, 22) print("PRESS SPACE TO PLAY", 10, 22)
end end
@@ -352,12 +371,12 @@ end
-- ----- GAME OVER ----- -- ----- GAME OVER -----
function update_gameover() function update_gameover()
-- Render congelat: ultim estat del joc + overlay "GAME OVER" -- Render congelat: ultim estat del joc + overlay "GAME OVER"
cls() neteja_fons()
pintar_mapa() pintar_mapa()
pintar_malos() pintar_malos()
pintar_pepe() pintar_pepe()
color(COLOR_LIGHT_RED, COLOR_BLACK) color(colors.title, colors.bg)
print("G A M E O V E R", 11, 12) print("G A M E O V E R", 11, 12)
pintar_hud() pintar_hud()
@@ -378,12 +397,12 @@ end
-- ----- ENTER NAME ----- -- ----- ENTER NAME -----
function update_entername() function update_entername()
cls() neteja_fons()
color(COLOR_LIGHT_RED, COLOR_BLACK) color(colors.title, colors.bg)
print("NOU RECORD!", 14, 10) print("NOU RECORD!", 14, 10)
color(COLOR_YELLOW, COLOR_BLACK) color(colors.diners, colors.bg)
print("SCORE "..string.format("%03d", hi_score), 15, 12) print("SCORE "..string.format("%03d", hi_score), 15, 12)
color(COLOR_WHITE, COLOR_BLACK) color(COLOR_WHITE, colors.bg)
print("NOM: "..nom_hi_score, 16, 15) print("NOM: "..nom_hi_score, 16, 15)
print("(A-Z)", 17, 17) print("(A-Z)", 17, 17)
@@ -429,7 +448,7 @@ function update_playing()
end end
-- Render -- Render
cls() neteja_fons()
pintar_mapa() pintar_mapa()
pintar_malos() pintar_malos()
pintar_pepe() pintar_pepe()
@@ -442,16 +461,16 @@ end
function init_malos() function init_malos()
malos = { malos = {
{ x= 9, y=2, color=COLOR_CYAN, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} }, { x= 9, y=2, color=colors.malo, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} },
{ x=20, y=2, color=COLOR_CYAN, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} }, { x=20, y=2, color=colors.malo, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} },
{ x=39, y=2, color=COLOR_CYAN, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} }, { x=39, y=2, color=colors.malo, estat=ESQUERRA, iaclock=0, carrega={ok=false, x=0, y=0} },
} }
end end
function pintar_malos() function pintar_malos()
for i = 1, NUM_MALOS do for i = 1, NUM_MALOS do
local m = malos[i] local m = malos[i]
color(m.color, COL_BUIT) color(m.color, colors.bg)
print(chr(glif[MALO_C]), m.x, m.y) print(chr(glif[MALO_C]), m.x, m.y)
end end
end end
@@ -515,10 +534,10 @@ function mort_malo(m)
if m.carrega.ok then if m.carrega.ok then
local c = mapa[m.carrega.x][m.carrega.y] local c = mapa[m.carrega.x][m.carrega.y]
c.tipo = DINERS c.tipo = DINERS
c.color = COL_DINERS c.color = colors.diners
end end
m.x = 39; m.y = 1 m.x = 39; m.y = 1
m.color = COLOR_CYAN m.color = colors.malo
m.estat = CAENT m.estat = CAENT
m.iaclock = 0 m.iaclock = 0
m.carrega.ok = false m.carrega.ok = false
@@ -572,7 +591,7 @@ function tic_malos()
-- agafar diners -- agafar diners
if tipo_a(m.x, m.y) == DINERS and not m.carrega.ok then if tipo_a(m.x, m.y) == DINERS and not m.carrega.ok then
mapa[m.x][m.y].tipo = BUIT mapa[m.x][m.y].tipo = BUIT
m.color = COLOR_LIGHT_CYAN m.color = colors.malo_carrega
m.carrega.ok = true m.carrega.ok = true
m.carrega.x = m.x m.carrega.x = m.x
m.carrega.y = m.y m.carrega.y = m.y
@@ -604,7 +623,7 @@ function check_mapa_complet()
for j = 1, MAP_H-2 do for j = 1, MAP_H-2 do
if mapa[0][j].tipo == PEDRA then break end if mapa[0][j].tipo == PEDRA then break end
mapa[0][j].tipo = ESCALA mapa[0][j].tipo = ESCALA
mapa[0][j].color = COL_ESCALA mapa[0][j].color = colors.escala
end end
end end
@@ -618,15 +637,15 @@ function check_mapa()
if t == 0 then if t == 0 then
c.temps = -1 c.temps = -1
c.tipo = PEDRA c.tipo = PEDRA
c.color = COL_PEDRA c.color = colors.pedra
elseif t == 1 or t == BLOC_OUT-1 then elseif t == 1 or t == BLOC_OUT-1 then
c.tipo = BLOC3; c.color = COL_PEDRA; c.temps = t - 1 c.tipo = BLOC3; c.color = colors.pedra; c.temps = t - 1
elseif t == 2 or t == BLOC_OUT-2 then elseif t == 2 or t == BLOC_OUT-2 then
c.tipo = BLOC2; c.color = COL_PEDRA; c.temps = t - 1 c.tipo = BLOC2; c.color = colors.pedra; c.temps = t - 1
elseif t == 3 or t == BLOC_OUT-3 then elseif t == 3 or t == BLOC_OUT-3 then
c.tipo = BLOC1; c.color = COL_PEDRA; c.temps = t - 1 c.tipo = BLOC1; c.color = colors.pedra; c.temps = t - 1
elseif t == 4 or t == BLOC_OUT-4 then elseif t == 4 or t == BLOC_OUT-4 then
c.tipo = BUIT; c.color = COL_BUIT; c.temps = t - 1 c.tipo = BUIT; c.color = colors.bg; c.temps = t - 1
elseif t > 0 then elseif t > 0 then
c.temps = t - 1 c.temps = t - 1
end end
@@ -638,7 +657,7 @@ end
-- HUD: rotul inferior amb level/score/vides/hi-score sobre banda blava -- HUD: rotul inferior amb level/score/vides/hi-score sobre banda blava
function pintar_hud() function pintar_hud()
color(COLOR_LIGHT_GRAY, COLOR_BLUE) color(colors.hud_text, colors.hud_bg)
local blank = " " local blank = " "
print(blank, 0, 25) print(blank, 0, 25)
print(blank, 0, 26) print(blank, 0, 26)
@@ -650,16 +669,24 @@ function pintar_hud()
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.
-- Despres del dofile, si l'usuari ha fet "colors = {bg=X}" en lloc d'assignar
-- camp a camp, hi haura claus que falten. Fem un merge amb les defaults
-- guardades per a que no quede res a nil.
function carregar_config() function carregar_config()
local saved = {}
for k, v in pairs(colors) do saved[k] = v end
pcall(dofile, "config.lua") pcall(dofile, "config.lua")
for k, v in pairs(saved) do
if colors[k] == nil then colors[k] = v end
end
end end
function init() function init()
carregar_config() carregar_config()
glif = SKINS[skin] or SKINS.custom glif = SKINS[skin] or SKINS.custom
mode(1) mode(1)
border(COLOR_BLUE) border(colors.border)
color(COLOR_LIGHT_GRAY, COLOR_BLACK) color(colors.bg, colors.bg) -- ink no importa, paper=bg perque el cls() final empleni amb bg
definir_glifs() definir_glifs()
carregar_records() carregar_records()
init_title() init_title()