105 lines
2.7 KiB
Lua
105 lines
2.7 KiB
Lua
require "mapa"
|
|
|
|
editor = {
|
|
mx = 0,
|
|
my = 0,
|
|
|
|
init = function(level_name)
|
|
game_update = editor.update
|
|
editor.new()
|
|
--if level_name then
|
|
-- editor.current_layer = 2
|
|
--end
|
|
end,
|
|
|
|
new = function()
|
|
mapa.new()
|
|
editor.current_layer = 1
|
|
editor.current_tile = 1
|
|
end,
|
|
|
|
update = function()
|
|
view.origin(mapa.x,mapa.y)
|
|
surf.cls(66)
|
|
mapa.draw(1)
|
|
--batman.draw()
|
|
mapa.draw(2)
|
|
|
|
map.surf(mapa.surf[editor.current_layer])
|
|
|
|
|
|
local mx,my = mouse.pos()
|
|
local tx = (mx//8)*8
|
|
local ty = (my//8)*8
|
|
draw.rect(tx-1,ty-1,10, 10, 9)
|
|
|
|
if key.press(key.TAB) then
|
|
game_update = editor.tile_picker_update
|
|
elseif key.press(key.RIGHT) then
|
|
mapa.x = mapa.x - 8
|
|
elseif key.press(key.LEFT) then
|
|
mapa.x = mapa.x + 8
|
|
elseif key.press(key.DOWN) then
|
|
mapa.y = mapa.y - 8
|
|
elseif key.press(key.UP) then
|
|
mapa.y = mapa.y + 8
|
|
elseif key.press(key.N1) then
|
|
editor.current_layer=1
|
|
elseif key.press(key.N2) then
|
|
editor.current_layer=2
|
|
elseif key.press(key.F) then
|
|
mapa.fill(tx//8, ty//8, map.tile(mx/8, my/8), editor.current_tile)
|
|
elseif key.down(key.LCTRL) and key.press(key.S) then
|
|
mapa.save()
|
|
elseif key.down(key.LCTRL) and key.press(key.L) then
|
|
mapa.load(1)
|
|
end
|
|
|
|
if mouse.down(mouse.LEFT) then
|
|
map.tile(mx/8, my/8, editor.current_tile)
|
|
elseif mouse.press(mouse.RIGHT) then
|
|
editor.current_tile = map.tile(mx/8, my/8)
|
|
end
|
|
|
|
view.origin(0,0)
|
|
draw.text(tostring(mx//8)..","..tostring(my//8),50,0,22)
|
|
|
|
mx,my = mouse.pos()
|
|
if key.down(key.SPACE) then
|
|
if editor.mx == -1 then
|
|
editor.mx,editor.my = mx,my
|
|
end
|
|
mapa.x = mapa.x + 8*(mx-editor.mx)
|
|
mapa.y = mapa.y + 8*(my-editor.my)
|
|
editor.mx,editor.my = mx,my
|
|
else
|
|
editor.mx = -1
|
|
end
|
|
|
|
text(tostring(editor.current_layer),0,0,22,42)
|
|
end,
|
|
|
|
tile_picker_update = function()
|
|
view.origin(0,0)
|
|
surf.cls(66)
|
|
pal.trans(255)
|
|
surf.source(tiles)
|
|
local sw,sh = surf.size(tiles)
|
|
draw.surf(0,0,sw,sh,0,0)
|
|
|
|
if key.press(key.ESCAPE) then
|
|
game_update = editor.update
|
|
end
|
|
|
|
local mx,my = mouse.pos()
|
|
local tx = (mx//8)*8
|
|
local ty = (my//8)*8
|
|
draw.rect(tx-1,ty-1,10, 10, 9)
|
|
if mouse.press(mouse.LEFT) then
|
|
editor.current_tile = (tx//8) + (ty//8) * (sw//8)
|
|
game_update = editor.update
|
|
|
|
end
|
|
|
|
end
|
|
} |