SCROLLING! I canviat a map

This commit is contained in:
2026-03-19 21:28:15 +01:00
parent f8669133c4
commit 4286eb27fa
4 changed files with 50 additions and 147 deletions

View File

@@ -3,12 +3,10 @@ require "mapa"
local viewport= require("viewport") local viewport= require("viewport")
local arcade_config = require("arcade_config") local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala local tile_w = arcade_config.tiles_width
local txr = arcade_config.tiles_per_row-1 local tile_h = arcade_config.tiles_height
local txr2 = arcade_config.tiles_per_row_base2 local res_w = arcade_config.resolucion.width
local toff= arcade_config.tiles_offset local res_h = arcade_config.resolucion.height
local tw = arcade_config.tiles_width
local th = arcade_config.tiles_height
local viewp = viewport.new() local viewp = viewport.new()
@@ -16,108 +14,14 @@ function game_init(menu)
game_update=update_game game_update=update_game
end end
-- function mapa_draw(hab) function render_map( sf_map, sf_tiles, x, y )
-- for ty=0,5 do map.surf(sf_map)
-- for tx=0,11 do map.cell(16, 16)
-- local tile=mapa[1+hab][1+tx+ty*12] surf.source(sf_tiles)
-- if tile~=256 and (tile<126 or mapa.step>4) then surf.target(0)
-- -- draw.surf((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8) view.origin(-x,-y)
-- local txr = arcade_config.tiles_per_row-1 map.draw()
-- local txr2 = arcade_config.tiles_per_row_base2 view.origin(0,0)
-- 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 render_view ( x, y )
local curr_ssurf = surf.source()
local curr_tsurf = surf.target()
local nroom, room_x, room_y, tile_offset_x, tile_offset_y = viewp:tile()
-- print("COORDS= "..x..", "..y)
-- print("ROOM= "..nroom)
-- print("RCOORDS= "..room_x..", "..room_y)
-- print("TILE_OFF= "..tile_offset_x..", "..tile_offset_y)
max_tiles_col = (arcade_config.resolucion.width/arcade_config.tiles_width)+1; -- Los que caben en una pantalla y 1 parcial
max_tiles_row = (arcade_config.resolucion.height/arcade_config.tiles_height)+1; -- Los que caben en una pantalla y 1 parcial
curr_room = nroom
curr_room_x = room_x
curr_room_y = room_y
surf.target(map_buffer_extra_V)
surf.cls(16)
surf.target(map_buffer_extra_H)
surf.cls(16)
surf.target(map_buffer)
surf.cls(16)
surf.source(tiles)
tile_y = room_y
for ty=0,max_tiles_row-1 do
tile_x = room_x
if tile_y>mapa_room_rows-1 then
nroom = nroom + 10
tile_y = 0
end
curr_room = nroom
for tx=0,max_tiles_col-1 do
if tile_x>mapa_room_cols-1 then
curr_room = curr_room+1
tile_x = 0
end
if curr_room >= 80 then
break
end
local tile=mapa[1+curr_room][1+tile_x+tile_y*mapa_room_cols]
-- print("R"..curr_room.." ("..tile_x..", "..tile_y..") > "..tile)
-- print(" TILE= "..tile)
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
if tx==0 and ty==max_tiles_row-1 then
surf.target(map_buffer_extra_H)
draw.surf((tile&txr)*tw,toff+(tile>>txr2)*th,tw,th,tx*tw,0)
surf.target(map_buffer)
elseif tx==max_tiles_col-1 then
surf.target(map_buffer_extra_V)
draw.surf((tile&txr)*tw,toff+(tile>>txr2)*th,tw,th,0,ty*th)
surf.target(map_buffer)
else
draw.surf((tile&txr)*tw,toff+(tile>>txr2)*th,tw,th,tx*tw,ty*th)
end
end
tile_x = tile_x+1
end
tile_y = tile_y+1
end
surf.source(map_buffer)
surf.target(0)
draw.surf(tile_offset_x,tile_offset_y,viewp.width,viewp.height,0,0,viewp.width,viewp.height)
surf.source(map_buffer_extra_V)
draw.surf(0, tile_offset_y, tile_offset_x, viewp.height, viewp.width-tile_offset_x, 0, tile_offset_x, viewp.height)
surf.source(map_buffer_extra_H)
draw.surf(tile_offset_x, 0,viewp.width,tile_offset_y,0,viewp.height-tile_offset_y,viewp.width,tile_offset_y)
surf.source(curr_ssurf)
surf.source(curr_tsurf)
end end
function update_game() function update_game()
@@ -130,8 +34,6 @@ function update_game()
-- surf.source(logo) -- surf.source(logo)
-- draw.surf(0,0,36,5,56,70,arcade_config.logo_sf.width,arcade_config.logo_sf.height) -- draw.surf(0,0,36,5,56,70,arcade_config.logo_sf.width,arcade_config.logo_sf.height)
-- render_view(10)
--- if abad.hurting == 0 then --- if abad.hurting == 0 then
--- draw_hab(abad.hab,0,0) --- draw_hab(abad.hab,0,0)
--- --text(abad.hab,1,1,2) --- --text(abad.hab,1,1,2)
@@ -156,37 +58,20 @@ function update_game()
--- end --- end
--- ---
--- mapa_update(abad.hab,cameras[current_camera].hab) --- mapa_update(abad.hab,cameras[current_camera].hab)
local vp_x, vp_y = viewp:position()
local vp_x, vp_y = viewp:position()
if key.down(keyRight) then if key.down(keyRight) then
if vp_x+1<=(arcade_config.tiles_width*mapa_room_cols*(mapa_rooms_per_piso))-(arcade_config.resolucion.width) then vp_x = vp_x+1 end if vp_x+1<=(tile_w*mapa_room_cols*(mapa_rooms_per_piso))-(res_w) then vp_x = vp_x+1 end
elseif key.down(keyLeft) then elseif key.down(keyLeft) then
if vp_x>0 then vp_x = vp_x-1 end if vp_x>0 then vp_x = vp_x-1 end
elseif key.down(keyUp) then elseif key.down(keyUp) then
if vp_y>0 then vp_y = vp_y -1 end if vp_y>0 then vp_y = vp_y -1 end
elseif key.down(keyDown) then elseif key.down(keyDown) then
if vp_y+1<=(arcade_config.tiles_height*mapa_room_rows*mapa_pisos)-(arcade_config.resolucion.height) then vp_y = vp_y+1 end if vp_y+1<=(tile_h*mapa_room_rows*mapa_pisos)-(res_h) then vp_y = vp_y+1 end
end end
viewp:position(vp_x, vp_y) viewp:position(vp_x, vp_y)
render_view(vp_x, vp_y) render_map(sf_mapa, tiles, vp_x, vp_y)
fps_print()
fps_print()
viewp:print() viewp:print()
end end
function draw_hab(hab,x,y,editing)
-- print(hab.." "..x.." "..y)
view.origin(x,y)
mapa_draw(hab)
-- if not editing then
-- for key,actor in pairs(actors) do
-- if actor.hab==hab then
-- actor:draw()
-- end
-- end
-- if imp.hab==hab then imp.draw() end
-- if bambolla.hab==hab then bambolla.draw() end
-- if cacau.hab==hab then cacau:draw() end
-- if fireball.hab==hab then fireball:draw() end
-- end
view.origin(0,0)
end

View File

@@ -2,7 +2,6 @@ require "fps"
require "fade" require "fade"
require "game" require "game"
-- require "mapa" -- require "mapa"
-- require "scenes" -- require "scenes"

View File

@@ -5,6 +5,35 @@ require "map"
local arcade_config = require("arcade_config") local arcade_config = require("arcade_config")
function load_tilemap( sf_mapa )
local mapa_tw, mapa_th = surf.size(sf_mapa)
local nrooms = mapa_rooms_per_piso*mapa_pisos
local x = 0
local y = 0
local yroom = 0
local xroom = 0
map.surf(sf_mapa)
for ty=0,mapa_th-1 do
if y == mapa_room_rows then
yroom = yroom + mapa_rooms_per_piso
y = 0
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
map.tile(tx, ty, tile)
x = x + 1
if x == mapa_room_cols then
x = 0
xroom = xroom + 1
end
end
y = y +1
end
end
function mini.init() function mini.init()
tiles=surf.load("tiles.gif") tiles=surf.load("tiles.gif")
surf.source(tiles) surf.source(tiles)
@@ -13,16 +42,8 @@ function mini.init()
logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height) logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height)
back=surf.new(arcade_config.surface.width,arcade_config.surface.height) back=surf.new(arcade_config.surface.width,arcade_config.surface.height)
-- buffer per a 3x3 habitacions sf_mapa=surf.new(mapa_room_cols*mapa_rooms_per_piso,mapa_room_rows*mapa_pisos)
-- local map_buffer_width = 3*mapa_room_cols*arcade_config.tiles_width load_tilemap( sf_mapa )
-- local map_buffer_height = 3*mapa_room_rows*arcade_config.tiles_height
-- local map_buffer_width = arcade_config.surface.width+2*arcade_config.tiles_width
local map_buffer_width = arcade_config.surface.width
-- local map_buffer_height = arcade_config.surface.height+2*arcade_config.tiles_height
local map_buffer_height = arcade_config.surface.height
map_buffer=surf.new(map_buffer_width,map_buffer_height)
map_buffer_extra_V=surf.new(arcade_config.tiles_width,map_buffer_height)
map_buffer_extra_H=surf.new(map_buffer_width,arcade_config.tiles_height)
fade.init() fade.init()
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height) textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)

View File

@@ -7,8 +7,6 @@ mapa_pisos = 8
-- 10 11 12 13 14 15 16 17 18 19 -- 10 11 12 13 14 15 16 17 18 19
-- ... -- ...
-- 70 71 72 73 74 75 76 77 78 79 -- 70 71 72 73 74 75 76 77 78 79
--
-- Hi ha una habitació 80 que no se que es
mapa={ mapa={
-- 1 -- 1