Factoritzades funcions per a conversió de coordenades.
[NEW] Tiles animats
This commit is contained in:
@@ -87,7 +87,7 @@ end
|
||||
function abad:move( x, y )
|
||||
self.x = x
|
||||
self.y = y
|
||||
local hab,xx, yy = arc_mapa_get_map_coords(x, y)
|
||||
local hab,xx, yy = coords.world_to_tile(x, y)
|
||||
self.hab = hab
|
||||
end
|
||||
|
||||
@@ -113,7 +113,7 @@ end
|
||||
|
||||
function abad_make_safe( force )
|
||||
force = force or false
|
||||
local hab, xx, yy = arc_mapa_get_map_coords(abad.x, abad.y)
|
||||
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
|
||||
if abad.safe.hab~=hab or force then
|
||||
abad.safe.hab=hab
|
||||
abad.safe.x=xx
|
||||
@@ -139,7 +139,7 @@ function abad_hurt(howmuch)
|
||||
-- abad.hab=abad.safe.hab
|
||||
-- abad.x=abad.safe.x
|
||||
-- abad.y=abad.safe.y
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( abad.safe.hab, abad.safe.x, abad.safe.y )
|
||||
local abad_x, abad_y = coords.room_to_world ( abad.safe.hab, abad.safe.x, abad.safe.y )
|
||||
abad:move(abad_x, abad_y)
|
||||
abad.hurting=60
|
||||
abad.update=abad_state_normal
|
||||
@@ -291,7 +291,7 @@ function abad_advance()
|
||||
abad.update=abad_state_normal
|
||||
abad.frame=0
|
||||
end
|
||||
local hab,xx, yy = arc_mapa_get_map_coords(abad.x, abad.y)
|
||||
local hab,xx, yy = coords.world_to_tile(abad.x, abad.y)
|
||||
abad.hab = hab
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ bol_gif_row = 3
|
||||
bol={hab=39,x=4,y=3,w=32,h=16,bb={x=0,y=0,w=16,h=8}}
|
||||
|
||||
function bol.init()
|
||||
local world_x, world_y = arc_mapa_get_coords(bol.hab,bol.x,bol.y)
|
||||
local world_x, world_y = coords.room_to_world(bol.hab,bol.x,bol.y)
|
||||
bol.x=world_x-8
|
||||
bol.y=world_y+2
|
||||
bol.update=bol.update
|
||||
|
||||
@@ -7,7 +7,7 @@ ch = arcade_config.character_height
|
||||
caco={}
|
||||
|
||||
function caco.new(_hab,_x,_y,_flip)
|
||||
local world_x, world_y = arc_mapa_get_coords(_hab,_x,_y)
|
||||
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
||||
return {hab=_hab,
|
||||
x=world_x,
|
||||
y=world_y,
|
||||
|
||||
127
data/coords.lua
Normal file
127
data/coords.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
-- Transformacio de coordenades entre el que es gastava en
|
||||
-- el Cacaus original i l'arcade
|
||||
|
||||
-- coords.lua
|
||||
local coords = {}
|
||||
|
||||
-- Configuración (se inyecta desde fuera)
|
||||
function coords.set_config(cfg)
|
||||
coords.TILE_W = cfg.tiles_width
|
||||
coords.TILE_H = cfg.tiles_height
|
||||
coords.ROOM_COLS = cfg.room_cols -- tiles por habitación en X
|
||||
coords.ROOM_ROWS = cfg.room_rows -- tiles por habitación en Y
|
||||
coords.ROOMS_PER_FLOOR = cfg.rooms_per_floor
|
||||
coords.ROOM_W = coords.TILE_W * coords.ROOM_COLS
|
||||
coords.ROOM_H = coords.TILE_H * coords.ROOM_ROWS
|
||||
end
|
||||
|
||||
-- -------------------------------------------------
|
||||
-- World (pixel) → tile en la surface de mini que guarda el mapa
|
||||
function coords.world_to_mini_tile(x, y)
|
||||
-- posició local dins de l'habitació (pixels)
|
||||
local map_x = math.floor(x / coords.TILE_W)
|
||||
local map_y = math.floor(y / coords.TILE_H)
|
||||
return map_x, map_y
|
||||
end
|
||||
|
||||
-- -------------------------------------------------
|
||||
-- World (pixel) → tile dins de l'habitació
|
||||
function coords.world_to_tile(x, y)
|
||||
local room = coords.world_to_room(x, y)
|
||||
|
||||
-- posició local dins de l'habitació (pixels)
|
||||
local local_x = x % coords.ROOM_W
|
||||
local local_y = y % coords.ROOM_H
|
||||
|
||||
-- coordenades del tile
|
||||
local tile_col = math.floor(local_x / coords.TILE_W)
|
||||
local tile_row = math.floor(local_y / coords.TILE_H)
|
||||
|
||||
-- offsets dins del tile
|
||||
local offset_x = local_x % coords.TILE_W
|
||||
local offset_y = local_y % coords.TILE_H
|
||||
|
||||
return room, tile_col, tile_row, offset_x, offset_y
|
||||
end
|
||||
|
||||
-- -------------------------------------------------
|
||||
-- World (pixel) → room index
|
||||
function coords.world_to_room(x, y)
|
||||
local room_col = math.floor(x / coords.ROOM_W)
|
||||
local room_row = math.floor(y / coords.ROOM_H)
|
||||
return room_row * coords.ROOMS_PER_FLOOR + room_col
|
||||
end
|
||||
|
||||
function coords.room_to_world(hab, tile_x, tile_y)
|
||||
-- La primera habitació es la 0
|
||||
-- El primer tile es 0
|
||||
local world_x = coords.TILE_W * ( (hab % coords.ROOMS_PER_FLOOR)*coords.ROOM_COLS + tile_x)
|
||||
local world_y = coords.TILE_H * (math.floor(hab / coords.ROOMS_PER_FLOOR)*coords.ROOM_ROWS + tile_y)
|
||||
|
||||
return world_x, world_y
|
||||
end
|
||||
|
||||
function coords.room_index_to_xy ( room, tile_idx )
|
||||
local x = (tile_idx-1) % coords.ROOM_COLS
|
||||
local y = math.floor((tile_idx-1) / coords.ROOM_COLS)
|
||||
|
||||
return x, y
|
||||
end
|
||||
|
||||
function coords.room_to_coord ( room, center )
|
||||
center = center or false
|
||||
|
||||
local col = room % coords.ROOMS_PER_FLOOR -- columna de l'habitació
|
||||
local row = math.floor(room / coords.ROOMS_PER_FLOOR) -- fila de l'habitació
|
||||
|
||||
local x = col * coords.ROOM_W
|
||||
local y = row * coords.ROOM_H
|
||||
|
||||
if center then
|
||||
-- moure x,y al centre de l'habitació
|
||||
x = x + (coords.ROOM_W // 2)
|
||||
y = y + (coords.ROOM_H // 2)
|
||||
end
|
||||
|
||||
return x, y
|
||||
end
|
||||
|
||||
-- local TILE_W = arcade_config.tiles_width
|
||||
-- local TILE_H = arcade_config.tiles_height
|
||||
-- local ROOM_COLS = mapa_room_cols
|
||||
-- local ROOM_ROWS = mapa_room_rows
|
||||
-- local ROOMS_PER_FLOOR = mapa_rooms_per_piso
|
||||
-- local ROOM_W = TILE_W*ROOM_COLS
|
||||
-- local ROOM_H = TILE_H*ROOM_ROWS
|
||||
|
||||
-- function coords_world_to_tile (x, y)
|
||||
-- local calc_col = math.floor(x / TILE_W) % ROOM_COLS
|
||||
-- local calc_row = math.floor(y / TILE_H) % ROOM_ROWS
|
||||
-- local calc_room = math.floor(y / (TILE_H * ROOM_ROWS))*ROOMS_PER_FLOOR + math.floor(x / ROOM_W)
|
||||
--
|
||||
-- local tile_offset_x = x - (calc_col * TILE_W) - ((calc_room % ROOMS_PER_FLOOR)*ROOM_W)
|
||||
-- local tile_offset_y = y - (calc_row * TILE_H) - ( math.floor(calc_room / ROOMS_PER_FLOOR)*ROOM_H)
|
||||
--
|
||||
-- -- room, x, y, offset x, offset y
|
||||
-- return calc_room, calc_col, calc_row, tile_offset_x, tile_offset_y
|
||||
-- end
|
||||
|
||||
-- function coords_world_to_room (x, y)
|
||||
-- local calc_col = math.floor(x / ROOM_W)
|
||||
-- local calc_row = math.floor(y / ROOM_H)
|
||||
--
|
||||
-- local calc_room = calc_row*ROOMS_PER_FLOOR+calc_col
|
||||
-- return calc_room
|
||||
-- end
|
||||
|
||||
return coords
|
||||
|
||||
-- local cfg = {
|
||||
-- tiles_width = arcade_config.tiles_width,
|
||||
-- tiles_height = arcade_config.tiles_height,
|
||||
-- room_cols = mapa_room_cols,
|
||||
-- room_rows = mapa_room_rows,
|
||||
-- rooms_per_floor = mapa_rooms_per_piso,
|
||||
-- }
|
||||
-- local coords = require "coords"
|
||||
-- coords.set_config(cfg)
|
||||
@@ -21,7 +21,7 @@ local res_h = arcade_config.resolucion.height
|
||||
local view_tile_id = false
|
||||
local view_checking_tile = false
|
||||
|
||||
viewp = viewport.new()
|
||||
viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
|
||||
viewp:position(0,0)
|
||||
|
||||
actors={}
|
||||
@@ -74,7 +74,7 @@ function game_init(menu)
|
||||
table.insert( actors, zombie.new(68, 3, 3,false) )
|
||||
table.insert( actors, zombie.new(73, 3, 3,false) )
|
||||
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 )
|
||||
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
||||
-- local abad_x, abad_y = arc_mapa_get_coords ( 77, 3, 2 )
|
||||
abad:move(abad_x, abad_y)
|
||||
abad_make_safe( true )
|
||||
@@ -140,14 +140,12 @@ function update_game()
|
||||
-- if vp_y+1<=(tile_h*mapa_room_rows*mapa_pisos)-(res_h) then vp_y = vp_y+1 end
|
||||
--end
|
||||
|
||||
load_tilemap( sf_mapa )
|
||||
|
||||
if key.press(key.N1) then
|
||||
local hab = abad.hab-1
|
||||
if hab<0 then hab=0 end
|
||||
local hab_x = 4
|
||||
local hab_y = 3
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( hab, hab_x, hab_y)
|
||||
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
|
||||
abad:move(abad_x, abad_y)
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
end
|
||||
@@ -156,16 +154,19 @@ function update_game()
|
||||
if hab<0 then hab=0 end
|
||||
local hab_x = 4
|
||||
local hab_y = 3
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( hab, hab_x, hab_y)
|
||||
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
|
||||
abad:move(abad_x, abad_y)
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
end
|
||||
if key.press(key.N0) then
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( 24, 1, 3 )
|
||||
local abad_x, abad_y = coords.room_to_world ( 24, 1, 3 )
|
||||
print(abad_x..", "..abad_y)
|
||||
abad:move(abad_x, abad_y)
|
||||
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
|
||||
end
|
||||
|
||||
arc_mapa_update()
|
||||
|
||||
for key,actor in pairs(actors) do
|
||||
actor:update()
|
||||
--if actor.hab==cacau.hab and actor~=abad then
|
||||
@@ -208,7 +209,7 @@ function update_game()
|
||||
viewp:print()
|
||||
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
|
||||
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y, true)
|
||||
local hab, xx, yy = arc_mapa_get_map_coords(abad.x, abad.y)
|
||||
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
|
||||
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
|
||||
-- msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
|
||||
msg_print(0,42," JH= "..abad.jump_height,true)
|
||||
@@ -271,7 +272,7 @@ end
|
||||
|
||||
function write_tile(x, y, yplus, print_type, align )
|
||||
local scr_x, scr_y = viewp:screen_coords(x, y)
|
||||
local hab, xx, yy = arc_mapa_get_map_coords(x, y)
|
||||
local hab, xx, yy = coords.world_to_tile(x, y)
|
||||
|
||||
yplus = yplus or 0
|
||||
print_type = print_type or false
|
||||
@@ -283,7 +284,8 @@ function write_tile(x, y, yplus, print_type, align )
|
||||
end
|
||||
|
||||
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
|
||||
local msg = mapa_get_tile(hab,xx,yy)
|
||||
-- local msg = mapa_get_tile(hab,xx,yy)
|
||||
local msg = arc_get_tile(x,y)
|
||||
if print_type then
|
||||
msg = msg.." "..arc_check_tile(x, y)
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ function gorro.init()
|
||||
-- gorro.x=habs[r][2]*8
|
||||
gorro.x=habs[r][2]
|
||||
|
||||
local world_x, world_y = arc_mapa_get_coords(gorro.hab,gorro.x,gorro.y)
|
||||
local world_x, world_y = coords.room_to_world(gorro.hab,gorro.x,gorro.y)
|
||||
gorro.x=world_x
|
||||
gorro.y=world_y
|
||||
gorro.update=gorro.update
|
||||
|
||||
@@ -10,7 +10,7 @@ gota_gif_row = 0
|
||||
gota={}
|
||||
|
||||
function gota.new(_hab,_x,_y,_freq,_x_offset, _y_offset)
|
||||
local world_x, world_y = arc_mapa_get_coords(_hab,_x,_y)
|
||||
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
||||
_x_offset = _x_offset or 0
|
||||
_y_offset = _y_offset or 0
|
||||
world_x = world_x+_x_offset
|
||||
|
||||
@@ -16,7 +16,7 @@ function gps.init()
|
||||
-- gps.x=habs[r][2]*8
|
||||
gps.x=habs[r][2]
|
||||
|
||||
local world_x, world_y = arc_mapa_get_coords(gps.hab,gps.x,gps.y)
|
||||
local world_x, world_y = coords.room_to_world(gps.hab,gps.x,gps.y)
|
||||
gps.x=world_x
|
||||
gps.y=world_y
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
arcade_config = require("arcade_config")
|
||||
coords = require "coords"
|
||||
|
||||
require "fps"
|
||||
require "fade"
|
||||
@@ -11,6 +12,26 @@ require "game"
|
||||
require "switches"
|
||||
-- require "scenes"
|
||||
|
||||
coords.set_config({
|
||||
tiles_width = arcade_config.tiles_width,
|
||||
tiles_height = arcade_config.tiles_height,
|
||||
room_cols = mapa_room_cols,
|
||||
room_rows = mapa_room_rows,
|
||||
rooms_per_floor = mapa_rooms_per_piso,
|
||||
})
|
||||
|
||||
function editor_to_map_tile(editor_tile)
|
||||
local result = 0
|
||||
if editor_tile<256 then result = editor_tile + arcade_config.tiles_offset end
|
||||
return result
|
||||
end
|
||||
|
||||
function map_to_editor_tile(map_tile)
|
||||
local result = map_tile - arcade_config.tiles_offset
|
||||
if map_tile==0 then result = 256 end
|
||||
return result
|
||||
end
|
||||
|
||||
function load_tilemap( sf_mapa )
|
||||
local mapa_tw, mapa_th = surf.size(sf_mapa)
|
||||
local nrooms = mapa_rooms_per_piso*mapa_pisos
|
||||
@@ -27,8 +48,7 @@ function load_tilemap( sf_mapa )
|
||||
end
|
||||
xroom = yroom
|
||||
for tx=0,mapa_tw-1 do
|
||||
local tile=mapa[1+xroom][1+x+y*mapa_room_cols]
|
||||
if tile<128 then tile= tile + 128 end
|
||||
local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols])
|
||||
map.tile(tx, ty, tile)
|
||||
x = x + 1
|
||||
if x == mapa_room_cols then
|
||||
@@ -91,9 +111,9 @@ function mini.init()
|
||||
btnCycle2 = tonumber(config.key("btncycle2")) or pad.LEFTSHOULDER
|
||||
btnPause = tonumber(config.key("btnpause")) or pad.START
|
||||
|
||||
-- game_init()
|
||||
-- logo_init()
|
||||
-- intro_init()
|
||||
logo_init()
|
||||
game_init()
|
||||
-- final_init()
|
||||
end
|
||||
|
||||
@@ -158,35 +178,3 @@ function arc_textB(str, x, y, col, colB)
|
||||
draw.surf(0,0,sw,sh,x,y,dw,dh)
|
||||
surf.source(curr_surf_src)
|
||||
end
|
||||
|
||||
function arc_textB2(str, x, y, col, colB)
|
||||
local ox, oy = view.origin()
|
||||
local curr_surf_tgt = surf.target()
|
||||
local curr_surf_src = surf.source()
|
||||
local sw = arcade_config.org_resolucion.width
|
||||
local sh = arcade_config.org_resolucion.height
|
||||
local dw = arcade_config.resolucion.width
|
||||
local dh = arcade_config.resolucion.height
|
||||
colB = colB or 16
|
||||
surf.target(textsf)
|
||||
view.origin(0,0)
|
||||
surf.cls(0)
|
||||
draw.text(str,0,0,colB)
|
||||
draw.text(str,1,0,colB)
|
||||
draw.text(str,2,0,colB)
|
||||
draw.text(str,0,1,colB)
|
||||
draw.text(str,2,1,colB)
|
||||
draw.text(str,0,2,colB)
|
||||
draw.text(str,1,2,colB)
|
||||
draw.text(str,2,2,colB)
|
||||
|
||||
draw.text(str,1,1,col)
|
||||
-- print("arc_B "..str)
|
||||
surf.source(textsf)
|
||||
|
||||
surf.target(curr_surf_tgt)
|
||||
view.origin(ox,oy)
|
||||
-- draw.surf(0,0,sw,sh,x,y,dw,dh)
|
||||
draw.surf(0,0)
|
||||
surf.source(curr_surf_src)
|
||||
end
|
||||
@@ -2,6 +2,7 @@ mapa_room_cols = 12; -- en quantitat de tiles
|
||||
mapa_room_rows = 6; -- en quantitat de tiles
|
||||
mapa_rooms_per_piso = 10
|
||||
mapa_pisos = 8
|
||||
mapa_empty_tile = 256
|
||||
|
||||
-- 0 1 2 3 4 5 6 7 8 9
|
||||
-- 10 11 12 13 14 15 16 17 18 19
|
||||
|
||||
215
data/mapa.lua
215
data/mapa.lua
@@ -78,27 +78,23 @@ function mapa_save()
|
||||
end
|
||||
|
||||
anim_tiles={113,114,112,116,117,115,119,120,118,122,121}
|
||||
function mapa_update(hab1,hab2)
|
||||
function arc_mapa_update()
|
||||
mapa.wait=mapa.wait+1
|
||||
|
||||
if mapa.wait==6 then
|
||||
mapa.wait=0
|
||||
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
|
||||
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
|
||||
if hab==hab2 then break end
|
||||
hab=hab2
|
||||
until false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,19 +115,6 @@ function mapa_draw(hab)
|
||||
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)
|
||||
print("MSTBI= R"..hab..", I"..index..", T="..mapa[1+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]
|
||||
@@ -145,74 +128,28 @@ function mapa_cycle_colors(hab)
|
||||
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
|
||||
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_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
|
||||
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 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
|
||||
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=arc_get_tile(world_x, world_y)
|
||||
local tile=map_to_editor_tile(arc_get_tile(world_x, world_y))
|
||||
if tile<8 then
|
||||
return tiletype.half
|
||||
elseif tile<15 then
|
||||
@@ -256,3 +193,115 @@ function mapa_draw_minimap()
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ function peu.init()
|
||||
-- peu.x=habs[r][2]*8
|
||||
peu.x=habs[r][2]
|
||||
|
||||
local world_x, world_y = arc_mapa_get_coords(peu.hab,peu.x,peu.y)
|
||||
local world_x, world_y = coords.room_to_world(peu.hab,peu.x,peu.y)
|
||||
peu.x=world_x
|
||||
peu.y=world_y
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ switches={
|
||||
|
||||
function switches.start(x, y)
|
||||
if switches.cooldown>0 then return end
|
||||
local hab, hx, hy = arc_mapa_get_map_coords(x, y)
|
||||
local hab, hx, hy = coords.world_to_tile(x, y)
|
||||
local tile_idx = (hx+hy*mapa_room_cols)+1
|
||||
print("Switch > "..x..", "..y.." / "..hab..", "..hx..", "..hy.." T="..tile_idx)
|
||||
mapa_set_tile_by_index(hab,tile_idx,57)
|
||||
-- mapa_set_tile_by_index(hab,tile_idx,57)
|
||||
arc_set_tile(x, y, editor_to_map_tile(57))
|
||||
switches.current_list=switches[hab+1][tile_idx]
|
||||
switches.current_index=2
|
||||
switches.wait=0
|
||||
@@ -38,7 +38,17 @@ function switches.update()
|
||||
|
||||
if switches.wait>=6 then
|
||||
switches.wait=0
|
||||
mapa_set_tile_by_index(switches.current_list[1]-1,switches.current_list[switches.current_index]+1,256)
|
||||
local hab= switches.current_list[1]-1
|
||||
local tile_idx= switches.current_list[switches.current_index]+1
|
||||
-- print(hab.." ("..tile_x..", "..tile_y..")")
|
||||
|
||||
-- local tile_x, tile_y = coords.room_index_to_xy ( hab, tile_idx )
|
||||
-- local world_x, world_y = coords.room_to_world(hab, tile_x, tile_y)
|
||||
-- arc_set_tile(world_x, world_y, 256)
|
||||
|
||||
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)
|
||||
|
||||
-- mapa_set_tile_by_index(switches.current_list[1]-1,switches.current_list[switches.current_index]+1,256)
|
||||
switches.current_index=switches.current_index+1
|
||||
if switches.current_index>#switches.current_list then
|
||||
switches.current_list=nil
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
require "map"
|
||||
|
||||
local arcade_config = require("arcade_config")
|
||||
|
||||
viewport={}
|
||||
|
||||
function viewport.new()
|
||||
function viewport.new(_width, _height)
|
||||
return { x=0, y=0,
|
||||
width=arcade_config.resolucion.width,
|
||||
height=arcade_config.resolucion.height,
|
||||
width=_width,
|
||||
height=_height,
|
||||
get=viewport.get,
|
||||
position=viewport.position,
|
||||
print=viewport.print,
|
||||
room=viewport.coord2room,
|
||||
roomXY= viewport.room2coord,
|
||||
tile= viewport.coord2tile,
|
||||
--roomXY= viewport.room2coord,
|
||||
tile= viewport.tile,
|
||||
last_tile= viewport.last_tile,
|
||||
screen_coords = viewport.screen_coords,
|
||||
inside = viewport.inside }
|
||||
end
|
||||
|
||||
function viewport:get()
|
||||
return self.x, self.y, self.x+self.width, self.y+self.height
|
||||
end
|
||||
|
||||
function viewport:screen_coords ( x, y )
|
||||
local scr_x = x-self.x
|
||||
local scr_y = y-self.y
|
||||
@@ -29,58 +33,69 @@ function viewport:inside( x, y, w, h )
|
||||
return result
|
||||
end
|
||||
|
||||
function viewport:coord2tile ()
|
||||
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
|
||||
-- function viewport:coord2tile (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 xx = x or self.x
|
||||
-- local yy = y or self.y
|
||||
--
|
||||
-- local calc_col = math.floor(xx / tw) % cols
|
||||
-- local calc_row = math.floor(yy / th) % rows
|
||||
-- local calc_room = math.floor(yy / (th * rows))*rooms_per_floor+math.floor(xx / (tw * cols))
|
||||
-- -- print("X= "..self.x.." / W="..tw.." / C= "..cols.." > "..calc_col)
|
||||
-- -- print("Y= "..self.y.." / H="..th.." / R= "..rows.." > "..calc_row)
|
||||
-- -- print("CR= "..calc_row.." / RF= "..rooms_per_floor.." / CC= "..calc_col)
|
||||
-- -- local tile_offset_x = self.x - (calc_col * tw * cols)
|
||||
-- -- local tile_offset_y = self.y - (calc_row * th * rows)
|
||||
-- local tile_offset_x = xx - (calc_col * tw) - ((calc_room%rooms_per_floor)*cols*tw)
|
||||
-- local tile_offset_y = yy - (calc_row * th) - ( math.floor(calc_room/10)*rows*th)
|
||||
-- -- print(self.x.." C"..calc_col.." W"..tw.." R"..calc_room.." c"..cols.." > "..tile_offset_x)
|
||||
-- -- room, x, y, offset x, offset y
|
||||
-- return calc_room, calc_col, calc_row, tile_offset_x, tile_offset_y
|
||||
-- end
|
||||
|
||||
local calc_col = math.floor(self.x / tw) % cols
|
||||
local calc_row = math.floor(self.y / th) % rows
|
||||
local calc_room = math.floor(self.y / (th * rows))*rooms_per_floor+math.floor(self.x / (tw * cols))
|
||||
-- print("X= "..self.x.." / W="..tw.." / C= "..cols.." > "..calc_col)
|
||||
-- print("Y= "..self.y.." / H="..th.." / R= "..rows.." > "..calc_row)
|
||||
-- print("CR= "..calc_row.." / RF= "..rooms_per_floor.." / CC= "..calc_col)
|
||||
-- local tile_offset_x = self.x - (calc_col * tw * cols)
|
||||
-- local tile_offset_y = self.y - (calc_row * th * rows)
|
||||
local tile_offset_x = self.x - (calc_col * tw) - ((calc_room%rooms_per_floor)*cols*tw)
|
||||
local tile_offset_y = self.y - (calc_row * th) - ( math.floor(calc_room/10)*rows*th)
|
||||
-- print(self.x.." C"..calc_col.." W"..tw.." R"..calc_room.." c"..cols.." > "..tile_offset_x)
|
||||
-- room, x, y, offset x, offset y
|
||||
return calc_room, calc_col, calc_row, tile_offset_x, tile_offset_y
|
||||
function viewport:tile ()
|
||||
return coords.world_to_tile(self.x, self.y)
|
||||
end
|
||||
|
||||
function viewport:last_tile ()
|
||||
return coords.world_to_tile(self.x+self.width, self.y+self.height)
|
||||
end
|
||||
|
||||
function viewport:coord2room ()
|
||||
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(self.x / (tw * cols))
|
||||
local calc_row = math.floor(self.y / (th * rows))
|
||||
|
||||
local calc_room = calc_row*rooms_per_floor+calc_col
|
||||
return calc_room
|
||||
return coords.world_to_room(self.x, self.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(self.x / (tw * cols))
|
||||
-- local calc_row = math.floor(self.y / (th * rows))
|
||||
--
|
||||
-- local calc_room = calc_row*rooms_per_floor+calc_col
|
||||
-- return calc_room
|
||||
end
|
||||
|
||||
function viewport:room2coord ( room )
|
||||
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 x = (room % rooms_per_floor) * cols * tw
|
||||
local y = math.floor(room/rooms_per_floor) * rows * th
|
||||
|
||||
local room_center_x_offset = (cols * tw) >> 1
|
||||
local room_center_y_offset = (rows * th) >> 1
|
||||
|
||||
-- return x+room_center_x_offset, y+room_center_y_offset
|
||||
return x, y
|
||||
end
|
||||
-- function viewport:room2coord ( room )
|
||||
-- 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 x = (room % rooms_per_floor) * cols * tw
|
||||
-- local y = math.floor(room/rooms_per_floor) * rows * th
|
||||
--
|
||||
-- local room_center_x_offset = (cols * tw) >> 1
|
||||
-- local room_center_y_offset = (rows * th) >> 1
|
||||
--
|
||||
-- -- return x+room_center_x_offset, y+room_center_y_offset
|
||||
-- return x, y
|
||||
-- end
|
||||
|
||||
function viewport:position(x, y)
|
||||
local nx = (x ~= nil) and x or self.x
|
||||
|
||||
@@ -5,7 +5,7 @@ ch = arcade_config.character_height
|
||||
zombie={}
|
||||
|
||||
function zombie.new(_hab,_x,_y,_flip)
|
||||
local world_x, world_y = arc_mapa_get_coords(_hab,_x,_y)
|
||||
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
|
||||
return {hab=_hab,
|
||||
x=world_x,
|
||||
y=world_y,
|
||||
|
||||
Reference in New Issue
Block a user