Files
ascii/tools/scredit.lua

107 lines
1.9 KiB
Lua

ind = 22
function init()
mode(1)
map = {}
col = {}
for i=0,1199 do
map[i] = 32
col[i] = 0x0f
end
map[ind] = 65
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 y=0,15 do
for x=0,15 do
poke(x+y*40, x+y*16)
poke(1200+x+y*40, sel_col)
end
end
for i=0,15 do
poke(1840+i, i<<4)
poke(1880+i, i<<4)
poke(640+i, 32)
poke(680+i, 32)
end
poke(1840, 15) poke(1880, 15)
poke(640+(sel_col&0xf), 203)
poke(680+(sel_col>>4), 203)
local mx, my = mousex(), mousey()
if mx<16 then
if my<16 then
poke(1200+(mx+my*40), 0x4e)
print(mx+my*40, 16, 13)
elseif my>=16 then
poke(mx+my*40, 144)
end
end
end
function update_picker()
local mx, my = mousex(), mousey()
if mousebutton(1) then
if mx<16 then
if my<16 then
sel_chr = mx+my*16
else
if my == 16 then
sel_col = (sel_col & 0xf0) + mx
elseif my == 17 then
sel_col = (sel_col & 0x0f) + (mx << 4)
end
end
end
end
end
function draw_map()
for i=0,1199 do
poke(i, map[i])
poke(1200+i, col[i])
end
local mx, my = mousex(), mousey()
if mousebutton(1) then
map[mx+my*40] = sel_chr
col[mx+my*40] = sel_col
end
if btn(KEY_SPACE) then
sel_chr = peek(mx+my*40)
sel_col = peek(1200+mx+my*40)
end
blink = blink - 1
if blink < 30 then
if blink==0 then blink = 60 end
local mx, my = mousex(), mousey()
local c = peek(1200+(mx+my*40))
poke(1200+(mx+my*40), c~0xff)
end
if btn(KEY_S) then
fileout("scr.bin", 0, 2400);
elseif btn(KEY_L) then
filein("scr.bin", 0, 2400);
for i=0,1199 do
map[i] = peek(i)
col[i] = peek(1200+i)
end
end
end