[WIP] Ja se pot scrollar per tot el mapa sense problemes. Ara falta que els tiles de les vores carreguen des del primer pixel i no només quan hi ha espai suficient
This commit is contained in:
@@ -2,7 +2,7 @@ require "map"
|
||||
|
||||
local arcade_config = require("arcade_config")
|
||||
|
||||
local viewport={}
|
||||
viewport={}
|
||||
|
||||
function viewport.new()
|
||||
return { x=0, y=0,
|
||||
@@ -11,10 +11,33 @@ function viewport.new()
|
||||
position=viewport.position,
|
||||
print=viewport.print,
|
||||
room=viewport.coord2room,
|
||||
roomXY= viewport.room2coord }
|
||||
roomXY= viewport.room2coord,
|
||||
tile= viewport.coord2tile }
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
function viewport:coord2room ()
|
||||
local tw = arcade_config.tiles_width
|
||||
local th = arcade_config.tiles_height
|
||||
@@ -29,15 +52,15 @@ function viewport:coord2room ()
|
||||
return calc_room
|
||||
end
|
||||
|
||||
function viewport:room2coord ( _room )
|
||||
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 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
|
||||
|
||||
Reference in New Issue
Block a user