DX: teclat configurable (cursors + Z/X per defecte)
This commit is contained in:
+14
@@ -46,3 +46,17 @@ skin = "native"
|
||||
-- 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
|
||||
|
||||
-- ====================================================================
|
||||
-- TECLES
|
||||
-- ====================================================================
|
||||
-- Mapeig per defecte: cursors per a moure's, Z/X per a fer forats.
|
||||
-- Pots usar qualsevol constant KEY_* del intérpret (KEY_A..KEY_Z,
|
||||
-- KEY_UP/DOWN/LEFT/RIGHT, KEY_SPACE, KEY_RETURN, ...).
|
||||
|
||||
-- keys.up = KEY_UP
|
||||
-- keys.down = KEY_DOWN
|
||||
-- keys.left = KEY_LEFT
|
||||
-- keys.right = KEY_RIGHT
|
||||
-- keys.dig_left = KEY_Z
|
||||
-- keys.dig_right = KEY_X
|
||||
|
||||
+25
-11
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user