DX: teclat configurable (cursors + Z/X per defecte)

This commit is contained in:
2026-05-15 13:22:02 +02:00
parent e34b5a20ce
commit 8f9ba8537e
2 changed files with 39 additions and 11 deletions
+25 -11
View File
@@ -39,6 +39,16 @@ SKINS = {
}
glif = SKINS.custom -- s'actualitza a init() segons la config
-- Tecles del joc — sobreescriuibles per config.lua.
keys = {
up = KEY_UP,
down = KEY_DOWN,
left = KEY_LEFT,
right = KEY_RIGHT,
dig_left = KEY_Z,
dig_right = KEY_X,
}
-- Paleta — tots els colors son sobreescriuibles per config.lua.
-- bg es el color del fons del nivell (pintat tant a les cel·les buides com
-- darrere de cada glif), per a que tot quede integrat en lloc de tindre
@@ -199,21 +209,21 @@ function tic_pepe()
local actual = tipo_a(pepe.x, pepe.y)
local sotto = tipo_a(pepe.x, pepe.y+1)
-- Moviment vertical: Q/A (com en RUNNER.PAS, son if/else)
if btn(KEY_Q) then
-- Moviment vertical (com en RUNNER.PAS, son if/else)
if btn(keys.up) then
if actual == ESCALA then pepe.y = pepe.y - 1 end
elseif btn(KEY_A) then
elseif btn(keys.down) then
if sotto == ESCALA or sotto == BUIT or sotto == DINERS then
pepe.y = pepe.y + 1
end
end
-- Moviment horitzontal: O/P (no es pot moure si esta caent)
if btn(KEY_O) then
-- Moviment horitzontal (no es pot moure si esta caent)
if btn(keys.left) then
if tipo_a(pepe.x-1, pepe.y) ~= PEDRA and pepe.estat ~= CAENT then
pepe.x = pepe.x - 1
end
elseif btn(KEY_P) then
elseif btn(keys.right) then
if tipo_a(pepe.x+1, pepe.y) ~= PEDRA and pepe.estat ~= CAENT then
pepe.x = pepe.x + 1
end
@@ -426,8 +436,8 @@ end
function update_playing()
-- Cavar es immediat (un sol forat per pulsacio)
if pepe.estat == NORMAL then
if btnp(KEY_SPACE) and pot_cavar(-1) then foradar(pepe.x-1, pepe.y+1); sfx_dig() end
if btnp(KEY_M) 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
if btnp(keys.dig_right) and pot_cavar( 1) then foradar(pepe.x+1, pepe.y+1); sfx_dig() end
end
-- Logica del joc: cada TICS frames
@@ -673,12 +683,16 @@ end
-- 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()
local saved = {}
for k, v in pairs(colors) do saved[k] = v end
local saved_colors, saved_keys = {}, {}
for k, v in pairs(colors) do saved_colors[k] = v end
for k, v in pairs(keys) do saved_keys[k] = v end
pcall(dofile, "config.lua")
for k, v in pairs(saved) do
for k, v in pairs(saved_colors) do
if colors[k] == nil then colors[k] = v end
end
for k, v in pairs(saved_keys) do
if keys[k] == nil then keys[k] = v end
end
end
function init()