100 lines
2.3 KiB
Lua
100 lines
2.3 KiB
Lua
--mapa={}
|
|
tiletype={void=0,stair=1,switch=2,half=3,block=4}
|
|
|
|
function mapa_new()
|
|
for my=0,7 do
|
|
for mx=0,9 do
|
|
local mi=1+mx+my*10
|
|
mapa[mi]={}
|
|
for ty=0,5 do
|
|
for tx=0,11 do
|
|
local tile=255
|
|
if mx==0 and tx==0 then
|
|
tile=16
|
|
elseif mx==4 and tx==11 then
|
|
tile=16
|
|
elseif ty==0 or ty==5 then
|
|
if tx%2==0 then
|
|
tile=20
|
|
else
|
|
tile=21
|
|
end
|
|
end
|
|
mapa[mi][1+tx+ty*12]=tile
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function mapa_save()
|
|
file = io.open("data/map.lua", "w")
|
|
io.output(file)
|
|
io.write("mapa={\n")
|
|
for i=1,80 do
|
|
io.write(" -- "..i.."\n {\n ")
|
|
for j=1,72 do
|
|
io.write(mapa[i][j]..",")
|
|
if j%12==0 then io.write("\n ") end
|
|
end
|
|
io.write("\n },\n")
|
|
end
|
|
io.write("}\n")
|
|
io.close(file)
|
|
end
|
|
|
|
function mapa_draw(hab)
|
|
for ty=0,5 do
|
|
for tx=0,11 do
|
|
local tile=mapa[1+hab][1+tx+ty*12]
|
|
if tile~=255 then
|
|
sspr((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function mapa_set_tile(hab,x,y,tile)
|
|
mapa[1+hab][1+x+y*12]=tile
|
|
end
|
|
|
|
function mapa_set_tile_by_index(hab,index,tile)
|
|
mapa[1+hab][index]=tile
|
|
end
|
|
|
|
function mapa_get_tile(hab,x,y)
|
|
return mapa[1+hab][1+x+y*12]
|
|
end
|
|
|
|
function mapa_cycle_colors(hab)
|
|
for i=1,72 do
|
|
local tile=mapa[1+hab][i]
|
|
if tile<4 then
|
|
tile=(tile+1)&3
|
|
elseif tile>=16 and tile<48 then
|
|
tile=tile+8
|
|
if tile>=48 then tile=tile-32 end
|
|
end
|
|
mapa[1+hab][i]=tile
|
|
end
|
|
end
|
|
|
|
function check_tile(hab,x,y)
|
|
local xx=min(11,max(0,flr(x/8)))
|
|
local yy=min(5,max(0,flr(y/8)))
|
|
--rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
|
|
|
local tile=mapa_get_tile(hab,xx,yy)
|
|
if tile<8 then
|
|
return tiletype.half
|
|
elseif tile<15 then
|
|
return tiletype.stair
|
|
elseif tile==15 then
|
|
return tiletype.switch
|
|
elseif tile<64 then
|
|
return tiletype.block
|
|
else
|
|
return tiletype.void
|
|
end
|
|
end
|