308 lines
8.8 KiB
Lua
308 lines
8.8 KiB
Lua
require "map"
|
|
|
|
local arcade_config = require("arcade_config")
|
|
|
|
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
|
|
mapa.wait=0
|
|
mapa.step=0
|
|
|
|
half_block_set={
|
|
[20] = true, [21] = true,
|
|
[22] = true, [28] = true,
|
|
[29] = true, [36] = true,
|
|
[37] = true, [44] = true,
|
|
[45] = true}
|
|
|
|
function mapa_is_half_block_tile (ntile)
|
|
return half_block_set[ntile]==true
|
|
end
|
|
|
|
function mapa_do_backup()
|
|
mapa_backup={}
|
|
for i=1,#mapa do
|
|
mapa_backup[i]={}
|
|
for j=1,#mapa[i] do
|
|
mapa_backup[i][j]=mapa[i][j]
|
|
end
|
|
end
|
|
end
|
|
|
|
function mapa_restore_backup()
|
|
for i=1,#mapa do
|
|
for j=1,#mapa[i] do
|
|
mapa[i][j]=mapa_backup[i][j]
|
|
end
|
|
end
|
|
end
|
|
|
|
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=256
|
|
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()
|
|
local 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
|
|
|
|
anim_tiles={113,114,112,116,117,115,119,120,118,122,121}
|
|
function arc_mapa_update()
|
|
mapa.wait=mapa.wait+1
|
|
|
|
if mapa.wait==6 then
|
|
mapa.wait = 0
|
|
mapa.step=(mapa.step+1)&31
|
|
|
|
local x0, y0, x1, y1 = viewp:get()
|
|
local tile = 0
|
|
for y=y0,y1,arcade_config.tiles_height do
|
|
for x=x0,x1,arcade_config.tiles_width do
|
|
tile=map_to_editor_tile(arc_get_tile(x,y))
|
|
if tile>=112 and tile<126 then
|
|
arc_set_tile(x,y,editor_to_map_tile(anim_tiles[tile-111]))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
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~=256 and (tile<126 or mapa.step>4) then
|
|
-- draw.surf((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8)
|
|
local txr = arcade_config.tiles_per_row-1
|
|
local txr2 = arcade_config.tiles_per_row_base2
|
|
local toff= arcade_config.tiles_offset
|
|
local tw = arcade_config.tiles_width
|
|
local th = arcade_config.tiles_height
|
|
draw.surf((tile&txr)*tw,toff+(tile>>txr2)*th,tw,th,tx*tw,ty*th)
|
|
end
|
|
end
|
|
end
|
|
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 arc_set_tile(world_x,world_y,tile)
|
|
local tx, ty = coords.world_to_mini_tile(world_x, world_y)
|
|
map.tile(tx, ty, tile)
|
|
end
|
|
|
|
function arc_set_tile_by_index(hab,index,tile)
|
|
local tile_x, tile_y = coords.room_index_to_xy ( hab, index )
|
|
local world_x, world_y = coords.room_to_world(hab, tile_x, tile_y)
|
|
arc_set_tile(world_x, world_y, tile)
|
|
end
|
|
|
|
function arc_get_tile(world_x,world_y)
|
|
local map_x, map_y = coords.world_to_mini_tile(world_x,world_y)
|
|
return map.tile(map_x,map_y)
|
|
end
|
|
|
|
function arc_check_tile(world_x,world_y)
|
|
-- tiletype => void=0 / nonpc=1 / stair=2 /
|
|
-- switch=3 / half=4 / block=5
|
|
|
|
local tile=map_to_editor_tile(arc_get_tile(world_x, world_y))
|
|
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
|
|
elseif tile==111 then
|
|
return tiletype.nonpc
|
|
else
|
|
return tiletype.void
|
|
end
|
|
end
|
|
|
|
pix={14,10,7,1,0,0,0,0,4,4,4,4,0,0,0,8,14,14,14,14,14,14,0,0,10,10,10,10,10,10,10,10,7,7,7,7,7,7,2,2,1,1,1,1,1,1,12,12,1,1,1,9,9,9,10,10,10,0,0,0,0,0,0,0}
|
|
|
|
function mapa_create_minimap()
|
|
minimap = surf.new(128,96)
|
|
surf.target(minimap)
|
|
for h=0,79 do
|
|
for y=0,5 do
|
|
for x=0,11 do
|
|
local tile=mapa[h+1][1+x+y*12]
|
|
if h==45 then
|
|
print(x..","..y.."="..tile)
|
|
end
|
|
if tile<64 then
|
|
surf.pixel(x+(h%10)*12,y+math.floor(h/10)*6,pix[1+tile])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
game_update=mapa_draw_minimap
|
|
end
|
|
|
|
function mapa_draw_minimap()
|
|
--print("HOLA")
|
|
surf.source(minimap)
|
|
surf.target(0)
|
|
surf.cls(16)
|
|
draw.surf(0,0,128*o2aX,96*o2Ax,0,0)
|
|
end
|
|
|
|
-- el el fitxer del mapa els tiles comencen per 0 pero estàn en el offset 128
|
|
-- Sustituida per arc_set_tile()
|
|
-- function mapa_set_tile(hab,x,y,tile)
|
|
-- print("MST= R"..hab..", "..x..", "..y.." -> "..tile)
|
|
--
|
|
-- -- NO es mante el mapa i la surface
|
|
-- -- mapa[1+hab][1+x+y*mapa_room_cols]=tile
|
|
--
|
|
-- local tx = (hab % mapa_rooms_per_piso)*mapa_room_cols+x
|
|
-- local ty = math.floor(hab / mapa_rooms_per_piso)*mapa_room_rows+y
|
|
-- -- if tile<arcade_config.tiles_offset then tile= tile + arcade_config.tiles_offset end
|
|
-- -- map.tile(tx, ty, tile)
|
|
-- map.tile(tx, ty, tile)
|
|
-- end
|
|
|
|
-- Sustituida per arc_set_tile_by_index()
|
|
-- function mapa_set_tile_by_index(hab,index,tile)
|
|
-- -- print("MSTBI= R"..hab..", I"..index..", T="..mapa[1+hab][index].." -> "..tile)
|
|
-- -- mapa[1+hab][index]=tile
|
|
-- local xx = ((index-1) % mapa_room_cols)
|
|
-- local yy = math.floor((index-1) / mapa_room_cols)
|
|
--
|
|
-- local tx = (hab % mapa_rooms_per_piso)*mapa_room_cols+xx
|
|
-- local ty = math.floor(hab / mapa_rooms_per_piso)*mapa_room_rows+yy
|
|
--
|
|
-- map.tile(tx, ty, tile+arcade_config.tiles_offset)
|
|
-- -- mapa_set_tile(hab, xx, yy, tile+arcade_config.tiles_offset)
|
|
-- end
|
|
|
|
-- sustituida per arc_get_tile
|
|
-- function mapa_get_tile(hab,x,y)
|
|
-- -- com se va mantenint tant mapa com la surface de map simultaniament
|
|
-- -- no deuria haver problemes
|
|
-- return mapa[1+hab][1+x+y*mapa_room_cols]
|
|
-- end
|
|
|
|
-- Sustituida per arc_mapa_update()
|
|
-- function mapa_update(hab1,hab2)
|
|
-- mapa.wait=mapa.wait+1
|
|
--
|
|
-- if mapa.wait==6 then
|
|
-- mapa.wait=0
|
|
-- mapa.step=(mapa.step+1)&31
|
|
--
|
|
-- local hab=hab1
|
|
--
|
|
-- repeat
|
|
-- for ty=0,5 do
|
|
-- for tx=0,11 do
|
|
-- local tile=mapa[1+hab][1+tx+ty*12]
|
|
-- if tile>=112 and tile<126 then
|
|
-- mapa[1+hab][1+tx+ty*12]=anim_tiles[tile-111]
|
|
-- end
|
|
-- end
|
|
-- end
|
|
-- if hab==hab2 then break end
|
|
-- hab=hab2
|
|
-- until false
|
|
-- end
|
|
-- end
|
|
|
|
-- function check_tile(hab,x,y)
|
|
-- msg_print(0,35,"c_t( "..hab..", "..x..", "..y.." )")
|
|
-- print("c_t( "..hab..", "..x..", "..y.." )")
|
|
-- -- local xx=math.min(11,math.max(0,math.floor(x/16)))
|
|
-- -- local yy=math.min(5,math.max(0,math.floor(y/16)))
|
|
-- --rect(xx*8,yy*8,xx*8+8,yy*8+8,3)
|
|
--
|
|
-- -- tiletype => void=0 / nonpc=1 / stair=2 /
|
|
-- -- switch=3 / half=4 / block=5
|
|
--
|
|
-- local tile=mapa_get_tile(hab,x,y)
|
|
-- 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
|
|
-- elseif tile==111 then
|
|
-- return tiletype.nonpc
|
|
-- else
|
|
-- return tiletype.void
|
|
-- end
|
|
-- end
|
|
|
|
-- Sustituida per coords.room_to_world()
|
|
--function arc_mapa_get_coords ( hab, tile_x , tile_y )
|
|
-- -- La primera habitació es la 0
|
|
-- -- El primer tile es 0
|
|
-- x = ((hab % 10)*mapa_room_cols + tile_x)*arcade_config.tiles_width
|
|
-- y = (math.floor(hab/10)*mapa_room_rows + tile_y)*arcade_config.tiles_height
|
|
--
|
|
-- return x, y
|
|
--end
|
|
|
|
-- Sustituida per coords.world_to_tile()
|
|
-- function arc_mapa_get_map_coords ( x, y )
|
|
-- local tw = arcade_config.tiles_width
|
|
-- local th = arcade_config.tiles_height
|
|
-- local cols = mapa_room_cols
|
|
-- local rows = mapa_room_rows
|
|
-- local rooms_per_floor = mapa_rooms_per_piso
|
|
--
|
|
-- local calc_col = math.floor(x / tw) % cols
|
|
-- local calc_row = math.floor(y / th) % rows
|
|
-- local calc_room = math.floor(y / (th * rows))*rooms_per_floor+math.floor(x / (tw * cols))
|
|
--
|
|
-- return calc_room, calc_col, calc_row
|
|
-- end
|