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.hud_bg = COLOR_BLACK -- fons del rotul inferior
|
||||||
-- colors.border = COLOR_BLUE -- vora exterior de la finestra
|
-- colors.border = COLOR_BLUE -- vora exterior de la finestra
|
||||||
-- colors.title = COLOR_LIGHT_RED -- GAME OVER / NOU RECORD
|
-- 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
|
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.
|
-- 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
|
-- 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
|
-- 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 actual = tipo_a(pepe.x, pepe.y)
|
||||||
local sotto = tipo_a(pepe.x, pepe.y+1)
|
local sotto = tipo_a(pepe.x, pepe.y+1)
|
||||||
|
|
||||||
-- Moviment vertical: Q/A (com en RUNNER.PAS, son if/else)
|
-- Moviment vertical (com en RUNNER.PAS, son if/else)
|
||||||
if btn(KEY_Q) then
|
if btn(keys.up) then
|
||||||
if actual == ESCALA then pepe.y = pepe.y - 1 end
|
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
|
if sotto == ESCALA or sotto == BUIT or sotto == DINERS then
|
||||||
pepe.y = pepe.y + 1
|
pepe.y = pepe.y + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Moviment horitzontal: O/P (no es pot moure si esta caent)
|
-- Moviment horitzontal (no es pot moure si esta caent)
|
||||||
if btn(KEY_O) then
|
if btn(keys.left) then
|
||||||
if tipo_a(pepe.x-1, pepe.y) ~= PEDRA and pepe.estat ~= CAENT then
|
if tipo_a(pepe.x-1, pepe.y) ~= PEDRA and pepe.estat ~= CAENT then
|
||||||
pepe.x = pepe.x - 1
|
pepe.x = pepe.x - 1
|
||||||
end
|
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
|
if tipo_a(pepe.x+1, pepe.y) ~= PEDRA and pepe.estat ~= CAENT then
|
||||||
pepe.x = pepe.x + 1
|
pepe.x = pepe.x + 1
|
||||||
end
|
end
|
||||||
@@ -426,8 +436,8 @@ end
|
|||||||
function update_playing()
|
function update_playing()
|
||||||
-- 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(KEY_SPACE) 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(KEY_M) 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
|
end
|
||||||
|
|
||||||
-- Logica del joc: cada TICS frames
|
-- 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
|
-- 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 = {}
|
local saved_colors, saved_keys = {}, {}
|
||||||
for k, v in pairs(colors) do saved[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
|
||||||
pcall(dofile, "config.lua")
|
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
|
if colors[k] == nil then colors[k] = v end
|
||||||
end
|
end
|
||||||
|
for k, v in pairs(saved_keys) do
|
||||||
|
if keys[k] == nil then keys[k] = v end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
|
|||||||
Reference in New Issue
Block a user