fase 2: Pepe en pantalla i moviment bàsic
This commit is contained in:
+25
-2
@@ -27,6 +27,7 @@ MAP_H = 25
|
||||
-- Estat
|
||||
mapa = {} -- mapa[x][y] = { tipo=, color=, temps= }
|
||||
level = 1
|
||||
pepe = { x=19, y=23, dibuix=PEPE_C, color=COLOR_WHITE, vides=0, estat=0 }
|
||||
|
||||
function definir_glifs()
|
||||
-- Cel·la buida (sobreescrivim el glif 0 del ROM, que no es buit)
|
||||
@@ -91,6 +92,26 @@ function pintar_mapa()
|
||||
end
|
||||
end
|
||||
|
||||
function pintar_pepe()
|
||||
color(pepe.color, COL_BUIT)
|
||||
print(chr(pepe.dibuix), pepe.x, pepe.y)
|
||||
end
|
||||
|
||||
-- Pepe pot entrar a una cel·la si no es pedra (de moment).
|
||||
-- Mes endavant afegirem regles d'escala, cuerda, gravetat, etc.
|
||||
function pot_entrar(x, y)
|
||||
if x < 0 or x >= MAP_W or y < 0 or y >= MAP_H then return false end
|
||||
return mapa[x][y].tipo ~= PEDRA
|
||||
end
|
||||
|
||||
function mou_pepe()
|
||||
-- Tecles originals: Q=amunt, A=avall, O=esquerra, P=dreta
|
||||
if btnp(KEY_Q) and pot_entrar(pepe.x, pepe.y-1) then pepe.y = pepe.y - 1 end
|
||||
if btnp(KEY_A) and pot_entrar(pepe.x, pepe.y+1) then pepe.y = pepe.y + 1 end
|
||||
if btnp(KEY_O) and pot_entrar(pepe.x-1, pepe.y) then pepe.x = pepe.x - 1 end
|
||||
if btnp(KEY_P) and pot_entrar(pepe.x+1, pepe.y) then pepe.x = pepe.x + 1 end
|
||||
end
|
||||
|
||||
function init()
|
||||
mode(1) -- 40x30 chars, color per cel·la
|
||||
border(COLOR_BLUE)
|
||||
@@ -98,9 +119,11 @@ function init()
|
||||
definir_glifs()
|
||||
carregar_mapa(level)
|
||||
cls() -- neteja despres del filein (que ha escrit a char_screen)
|
||||
pintar_mapa()
|
||||
end
|
||||
|
||||
function update()
|
||||
-- Fase 1: nomes render estatic, res que actualitzar encara
|
||||
mou_pepe()
|
||||
cls()
|
||||
pintar_mapa()
|
||||
pintar_pepe()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user