- [NEW] F1, F2 i F3 per al zoom i fullscreen
- [NEW] [tools/scredit.lua] C per a borrar pantalla en el caracter seleccionar, F per a flood fill
This commit is contained in:
@@ -69,6 +69,50 @@ function update_picker()
|
||||
end
|
||||
end
|
||||
|
||||
local W, H = 40, 30
|
||||
|
||||
function flood_fill(x, y)
|
||||
-- índice inicial
|
||||
local idx0 = x + y * W
|
||||
local target_chr = map[idx0]
|
||||
local target_col = col[idx0]
|
||||
|
||||
-- Si ya está pintado con lo que queremos, no hacemos nada
|
||||
if target_chr == sel_chr and target_col == sel_col then
|
||||
return
|
||||
end
|
||||
|
||||
-- Pila para DFS iterativo
|
||||
local stack = {}
|
||||
local sp = 1
|
||||
stack[sp] = {x = x, y = y}
|
||||
|
||||
while sp > 0 do
|
||||
local p = stack[sp]
|
||||
sp = sp - 1
|
||||
|
||||
local px, py = p.x, p.y
|
||||
|
||||
-- Comprobación de límites
|
||||
if px >= 0 and px < W and py >= 0 and py < H then
|
||||
local idx = px + py * W
|
||||
|
||||
-- ¿Coincide con el color original?
|
||||
if map[idx] == target_chr and col[idx] == target_col then
|
||||
-- Pintar
|
||||
map[idx] = sel_chr
|
||||
col[idx] = sel_col
|
||||
|
||||
-- Añadir vecinos
|
||||
sp = sp + 1; stack[sp] = {x = px+1, y = py}
|
||||
sp = sp + 1; stack[sp] = {x = px-1, y = py}
|
||||
sp = sp + 1; stack[sp] = {x = px, y = py+1}
|
||||
sp = sp + 1; stack[sp] = {x = px, y = py-1}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function draw_map()
|
||||
for i=0,1199 do
|
||||
poke(i, map[i])
|
||||
@@ -107,5 +151,14 @@ function draw_map()
|
||||
col[i] = peek(1200+i)
|
||||
end
|
||||
|
||||
elseif btn(KEY_C) then
|
||||
for y=0,29 do
|
||||
for x=0,39 do
|
||||
map[x+y*40] = sel_chr
|
||||
col[x+y*40] = sel_col
|
||||
end
|
||||
end
|
||||
elseif btn(KEY_F) then
|
||||
flood_fill(mousex(),mousey())
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user