- Classe mapa pot guardar i carregar

- [WIP] Editor bàsic
- Classe textbox
This commit is contained in:
2023-01-27 19:05:35 +01:00
parent 43ac9f26a2
commit c679a6dc39
7 changed files with 169 additions and 17 deletions

View File

@@ -1,7 +1,62 @@
function editor_init()
set_update(editor_update)
end
editor={
paused=true,
cam={x=0,y=0},
selected_tile=3,
function editor_update()
end
init=function()
set_update(editor.update)
editor.show_menu()
end,
show_menu=function()
menu.show({ {"NEW MAP", editor.new},
{"LOAD MAP", function() textbox.show("FILENAME TO LOAD:",editor.load, mapa.name) end},
{"SAVE MAP", function() if mapa.name~=nil then editor.save(mapa.name) else textbox.show("FILENAME TO SAVE:",editor.save, mapa.name) end end},
-- {"BACK TO EDITOR", function() editor.paused=false end},
{"EXIT", main_init},
-- {"ENNER LLOR NEIM", function() textbox.show("PELANDRUSC!") end}
}, function()editor.paused=false end)
end,
update=function()
cls()
camera(editor.cam.x, editor.cam.y)
map(0,0,0,0,mapa.w, mapa.h)
local mx,my=mousex()+editor.cam.x,mousey()+editor.cam.y
local tx,ty=mx>>3,my>>3
local rx,ry=tx<<3,ty<<3
rect(rx-1, ry-1, rx+8, ry+8, 10)
camera(0,0)
if not editor.paused then
if mbtn(1) then
mset(tx,ty,editor.selected_tile)
end
if btnp(KEY_RIGHT) then editor.cam.x=editor.cam.x+8 end
if btnp(KEY_LEFT) then editor.cam.x=editor.cam.x-8 end
if btnp(KEY_UP) then editor.cam.y=editor.cam.y-8 end
if btnp(KEY_DOWN) then editor.cam.y=editor.cam.y+8 end
if btnp(KEY_ESCAPE) then
editor.paused=true
editor.show_menu()
end
end
end,
new=function()
mapa.new(128,128)
editor.paused=false
end,
save=function(filename)
mapa.save(filename)
editor.paused=false
end,
load=function(filename)
mapa.load(filename)
editor.paused=false
end
}