Files
ascii/tools/mapedit.lua
2022-02-18 17:23:22 +01:00

108 lines
2.3 KiB
Lua

function init()
mode(2)
map = {}
col = {}
for i=0,299 do
map[i] = 32
col[i] = 0x0f
end
sel_col = 0x0f
sel_chr = 65
end
blink=30
function update()
if btn(KEY_TAB) then
draw_picker()
update_picker()
else
draw_map()
--update_map()
end
end
function draw_picker()
for i=0,255 do
poke(i, i)
poke(300+i, sel_col)
end
for i=0,15 do
poke(580+i, i<<4)
poke(560+i, i<<4)
poke(280+i, 32)
poke(260+i, 32)
end
poke(580, 15) poke(560, 15)
poke(260+(sel_col&0xf), 203)
poke(280+(sel_col>>4), 203)
local mx, my = mousex(), mousey()
if my<13 then
poke(300+(mx+my*20), 0x4e)
print(mx+my*20, 16, 13)
elseif my>=13 then
poke(mx+my*20, 144)
end
end
function update_picker()
local mx, my = mousex(), mousey()
if mousebutton(1) then
if my<13 then
sel_chr = mx+my*20
else
if mx < 16 then
if my == 13 then
sel_col = (sel_col & 0xf0) + mx
else
sel_col = (sel_col & 0x0f) + (mx << 4)
end
end
end
end
end
function draw_map()
for i=0,299 do
poke(i, map[i])
poke(300+i, col[i])
end
local mx, my = mousex(), mousey()
if mousebutton(1) then
map[mx+my*20] = sel_chr
col[mx+my*20] = sel_col
end
if mousebutton(3) then
col[mx+my*20] = sel_col
end
if btn(KEY_SPACE) then
sel_chr = peek(mx+my*20)
sel_col = peek(300+mx+my*20)
end
if btnp(KEY_UP) then for i=20,299 do map[i-20]=map[i]col[i-20]=col[i] end end
if btnp(KEY_DOWN) then for i=279,0,-1 do map[i+20]=map[i]col[i+20]=col[i] end end
if btnp(KEY_LEFT) then for i=0,298 do map[i]=map[i+1]col[i]=col[i+1] end end
if btnp(KEY_RIGHT) then for i=299,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
blink = blink - 1
if blink < 30 then
if blink==0 then blink = 60 end
local mx, my = mousex(), mousey()
local c = peek(300+(mx+my*20))
poke(300+(mx+my*20), c~0xff)
end
if btn(KEY_S) then
fileout("map.bin", 0, 600);
elseif btn(KEY_L) then
filein("map.bin", 0, 600);
for i=0,299 do
map[i] = peek(i)
col[i] = peek(300+i)
end
end
end