- [NEW] Nous tiles - [NEW] Batman ja puja i baixa per cordes/cadenes - [NEW] El batarang es mes visible - [NEW] el ganxo es mes visible
103 lines
3.1 KiB
Lua
103 lines
3.1 KiB
Lua
|
|
mapa = {
|
|
num = 1,
|
|
surf = {nil,nil},
|
|
x = 0,
|
|
y = 0,
|
|
|
|
new = function()
|
|
mapa.num = 1
|
|
mapa.surf[1] = surf.new(256,256)
|
|
mapa.surf[2] = surf.new(256,256)
|
|
mapa.x = 0
|
|
mapa.y = 0
|
|
end,
|
|
|
|
load = function(level)
|
|
local base_name = "level" .. tostring(level)
|
|
local file = io.open("data/" .. base_name .. ".lev", "r")
|
|
if file then
|
|
for line in file:lines() do
|
|
local key,value = line:match("^(.+)=(.+)$")
|
|
if key and value then
|
|
if key == "start-x" then
|
|
mapa.x = tonumber(value)
|
|
elseif key == "start-y" then
|
|
mapa.y = tonumber(value)
|
|
end
|
|
end
|
|
end
|
|
mapa.num = level
|
|
if mapa.surf[1] then surf.free(mapa.surf[1]) end
|
|
if mapa.surf[2] then surf.free(mapa.surf[2]) end
|
|
mapa.surf[1] = surf.load(base_name .. "_1.gif")
|
|
mapa.surf[2] = surf.load(base_name .. "_2.gif")
|
|
else
|
|
print("No s'ha trobat l'arxiu!")
|
|
end
|
|
end,
|
|
|
|
save = function()
|
|
local base_name = "level" .. tostring(mapa.num)
|
|
local file = io.open("data/" .. base_name .. ".lev", "w")
|
|
if file then
|
|
file:write("start-x=" .. tostring(mapa.x) .. "\n")
|
|
file:write("start-y=" .. tostring(mapa.y) .. "\n")
|
|
end
|
|
surf.save(mapa.surf[1], "data/" .. base_name .. "_1.gif")
|
|
surf.save(mapa.surf[2], "data/" .. base_name .. "_2.gif")
|
|
end,
|
|
|
|
draw = function(layer)
|
|
pal.trans(0)
|
|
surf.source(tiles)
|
|
map.surf(mapa.surf[layer])
|
|
map.draw()
|
|
map.surf(mapa.surf[1])
|
|
end,
|
|
|
|
fill = function(x, y, tile, fill_tile)
|
|
local stack = {}
|
|
table.insert(stack, {x = x, y = y})
|
|
|
|
while #stack > 0 do
|
|
local mw, mh = surf.size(map.surf[1])
|
|
local pos = table.remove(stack)
|
|
local px, py = pos.x, pos.y
|
|
|
|
map.tile(px, py, fill_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,
|
|
|
|
isSolid = function(x, y)
|
|
local tile = map.tile(x, y)
|
|
return (tile == 32) or (tile == 33) or (tile==36) or (tile==37) or (tile==42) or (tile==44) or (tile==45) or (tile==47)
|
|
end,
|
|
|
|
isBlock = function(x, y)
|
|
local tile = map.tile(x, y)
|
|
return (tile == 32)
|
|
end,
|
|
|
|
isPlatform = function(x, y)
|
|
local tile = map.tile(x, y)
|
|
return (tile == 33) or (tile==36) or (tile==37)
|
|
end,
|
|
|
|
isStairs = function(x, y)
|
|
local tile = map.tile(x, y)
|
|
return (tile>33) and (tile<40)
|
|
end,
|
|
|
|
isRope = function(x, y)
|
|
local tile = map.tile(x, y)
|
|
return (tile==40) or (tile==41)
|
|
end,
|
|
|
|
} |