Files
cacaus-arcade/data/mapa.lua

257 lines
6.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 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 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_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)
-- 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
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
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
function arc_get_tile(world_x,world_y)
-- local xx=math.min(11,math.max(0,math.floor(x/8)))
-- local yy=math.min(5,math.max(0,math.floor(y/8)))
--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 hab, xx, yy = arc_mapa_get_map_coords(world_x, world_y)
-- print("ARC_GT= "..hab.."> "..x..", "..y.." => "..tile)
local tile=mapa_get_tile(hab,xx,yy)
return tile
end
function arc_check_tile(world_x,world_y)
-- tiletype => void=0 / nonpc=1 / stair=2 /
-- switch=3 / half=4 / block=5
local 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