Intentant fer scroll

This commit is contained in:
2026-03-18 21:04:50 +01:00
parent 59fc474770
commit ef277ee9b2
5 changed files with 142 additions and 82 deletions

64
data/viewport.lua Normal file
View File

@@ -0,0 +1,64 @@
require "map"
local arcade_config = require("arcade_config")
local viewport={}
function viewport.new()
return { x=0, y=0,
width=arcade_config.resolucion.width,
height=arcade_config.resolucion.height,
position=viewport.position,
print=viewport.print,
room=viewport.coord2room,
roomXY=viewport.room2coord }
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
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
end
function viewport:position(x, y)
local nx = (x ~= nil) and x or self.x
local ny = (y ~= nil) and y or self.y
self.x = nx
self.y = ny
return self.x, self.y
end
function viewport:print()
local room = self:room()
draw.rectf(0,7,45,14,16)
draw.text("X="..self.x.." , Y= "..self.y..", R"..room,1,8,2)
end
return viewport