- Implementat el segon layer
- Implementat resizar el mapa
This commit is contained in:
@@ -15,12 +15,56 @@ editor={
|
||||
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},
|
||||
{mapa.front_layer and "DISABLE FRONT LAYER" or "ENABLE FRONT LAYER", editor.toggle_front_layer},
|
||||
{"RESIZE MAP", editor.resize},
|
||||
{"EXIT", main_init},
|
||||
-- {"ENNER LLOR NEIM", function() textbox.show("PELANDRUSC!") end}
|
||||
}, function()editor.paused=false end)
|
||||
end,
|
||||
|
||||
toggle_front_layer=function()
|
||||
if not mapa.front_layer then
|
||||
mapa.front_layer=newsurf(mapa.w,mapa.h)
|
||||
editor.editing_front_layer=true
|
||||
setmap(mapa.front_layer)
|
||||
for y=0,mapa.h-1 do
|
||||
for x=0,mapa.w-1 do
|
||||
mset(x,y,0)
|
||||
end
|
||||
end
|
||||
else
|
||||
mapa.front_layer=nil
|
||||
end
|
||||
editor.paused=false
|
||||
end,
|
||||
|
||||
resize=function()
|
||||
textbox.show("NEW MAP WIDTH:",function(value)
|
||||
editor.new_w=value
|
||||
textbox.show("NEW MAP HEIGHT:", function(value)
|
||||
editor.new_h=value
|
||||
editor.do_resize()
|
||||
end, tostring(mapa.h))
|
||||
end, tostring(mapa.w))
|
||||
end,
|
||||
|
||||
do_resize=function()
|
||||
local old_surface= mapa.surface
|
||||
mapa.w=tonumber(editor.new_w)
|
||||
mapa.h=tonumber(editor.new_h)
|
||||
mapa.surface=newsurf(mapa.w,mapa.h)
|
||||
for y=0,mapa.h-1 do
|
||||
for x=0,mapa.w-1 do
|
||||
setmap(old_surface)
|
||||
local value=mget(x,y)
|
||||
setmap(mapa.surface)
|
||||
mset(x,y,value)
|
||||
end
|
||||
end
|
||||
freesurf(old_surface)
|
||||
setmap(mapa.surface)
|
||||
editor.paused=false
|
||||
end,
|
||||
|
||||
floodfill=function(x,y,tile)
|
||||
local t=mget(x,y)
|
||||
mset(x,y,tile)
|
||||
@@ -92,8 +136,18 @@ editor={
|
||||
cls()
|
||||
camera(editor.cam.x, editor.cam.y)
|
||||
setsource(tiles)
|
||||
setmap(mapa.surface)
|
||||
map(0,0,0,0,mapa.w, mapa.h)
|
||||
|
||||
if mapa.front_layer then
|
||||
setmap(mapa.front_layer)
|
||||
map(0,0,0,0,mapa.w, mapa.h)
|
||||
end
|
||||
if editor.editing_front_layer then
|
||||
setmap(mapa.front_layer)
|
||||
text("EDITING FRONT LAYER",12,2,10)
|
||||
else
|
||||
setmap(mapa.surface)
|
||||
end
|
||||
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
|
||||
@@ -149,6 +203,13 @@ editor={
|
||||
if btnp(KEY_F) then
|
||||
editor.floodfill(tx,ty,editor.brush.tiles[1])
|
||||
end
|
||||
if btnp(KEY_1) then
|
||||
if editor.editing_front_layer then
|
||||
editor.editing_front_layer=nil
|
||||
else
|
||||
editor.editing_front_layer=true
|
||||
end
|
||||
end
|
||||
if btnp(KEY_RETURN) then
|
||||
editor.brush.tiles[1]=mget(tx,ty)
|
||||
end
|
||||
@@ -188,6 +249,7 @@ editor={
|
||||
|
||||
new=function()
|
||||
mapa.new(128,128)
|
||||
editor.editing_front_layer=nil
|
||||
editor.paused=false
|
||||
end,
|
||||
|
||||
@@ -198,6 +260,7 @@ editor={
|
||||
|
||||
load=function(filename)
|
||||
mapa.load(filename)
|
||||
editor.editing_front_layer=nil
|
||||
editor.paused=false
|
||||
end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user