- [FIX] Llevat tot el relacionat amb codi en C/C++
- [NEW] Fulla d'sprites de Batman - [NEW] Codi base de mini en Lua - [WIP] Treballant en el editor - [NEW] Fulla bàsica de tiles - [NEW] Afegida paleta actual
This commit is contained in:
120
data/editor.lua
Normal file
120
data/editor.lua
Normal file
@@ -0,0 +1,120 @@
|
||||
editor = {
|
||||
num = 1,
|
||||
map_surf = {nil,nil},
|
||||
current_layer = 1,
|
||||
current_tile = 1,
|
||||
ox = 0,
|
||||
oy = 0,
|
||||
|
||||
init = function(level_name)
|
||||
game_update = editor.update
|
||||
editor.new()
|
||||
--if level_name then
|
||||
-- editor.current_layer = 2
|
||||
--end
|
||||
end,
|
||||
|
||||
new = function()
|
||||
editor.num = 1
|
||||
editor.map_surf[1] = surf.new(256,256)
|
||||
editor.map_surf[2] = surf.new(256,256)
|
||||
editor.current_layer = 1
|
||||
editor.current_tile = 1
|
||||
editor.ox = 0
|
||||
editor.oy = 0
|
||||
end,
|
||||
|
||||
save = function()
|
||||
local base_name = "level" + tostring(editor.num)
|
||||
|
||||
end,
|
||||
|
||||
update = function()
|
||||
view.origin(editor.ox,editor.oy)
|
||||
surf.cls(66)
|
||||
pal.trans(0)
|
||||
surf.source(tiles)
|
||||
map.surf(editor.map_surf[1])
|
||||
map.draw()
|
||||
map.surf(editor.map_surf[2])
|
||||
map.draw()
|
||||
map.surf(editor.map_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
|
||||
editor.ox = editor.ox - 8
|
||||
elseif key.press(key.LEFT) then
|
||||
editor.ox = editor.ox + 8
|
||||
elseif key.press(key.DOWN) then
|
||||
editor.oy = editor.oy - 8
|
||||
elseif key.press(key.UP) then
|
||||
editor.oy = editor.oy + 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.N2) then
|
||||
editor.current_layer=2
|
||||
elseif key.press(key.F) then
|
||||
editor.fill(tx//8, ty//8, map.tile(mx/8, my/8))
|
||||
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)
|
||||
text(tostring(editor.current_layer),0,0,22,42)
|
||||
end,
|
||||
|
||||
fill = function(x, y, tile)
|
||||
local stack = {}
|
||||
table.insert(stack, {x = x, y = y})
|
||||
|
||||
while #stack > 0 do
|
||||
local mw, mh = surf.size(editor.map_surf[1])
|
||||
local pos = table.remove(stack)
|
||||
local px, py = pos.x, pos.y
|
||||
|
||||
map.tile(px, py, editor.current_tile)
|
||||
|
||||
if px<mw-1 and map.tile(px+1, py) == tile then table.insert(stack, {x = px + 1, y = py}) end
|
||||
if px>0 and map.tile(px-1, py) == tile then table.insert(stack, {x = px - 1, y = py}) end
|
||||
if py<mh-1 and map.tile(px, py+1) == tile then table.insert(stack, {x = px, y = py + 1}) end
|
||||
if py>0 and map.tile(px, py-1) == tile then table.insert(stack, {x = px, y = py - 1}) end
|
||||
|
||||
end
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user