[WIP] Lluita contra jefes

-- El viewport ja es fixa i es solta
-- L'escenari ja se modifica i se restaura
This commit is contained in:
2026-04-04 22:00:51 +02:00
parent 9bb372a70b
commit b2cb8698b4
6 changed files with 117 additions and 78 deletions

View File

@@ -14,7 +14,25 @@ function viewport.new(_width, _height)
tile= viewport.tile,
last_tile= viewport.last_tile,
screen_coords = viewport.screen_coords,
inside = viewport.inside }
inside = viewport.inside,
fixed = viewport.fixed,
free_move = viewport.free_move,
range = nil, -- rang de moviment quan està fixat {r= , l=, u=, d= }
fixed_coord = nil, -- coordenades fixades
smooth_adjust = nil,
adjust_speed = 2
}
end
function viewport:fixed(range)
self.range = range
self.fixed_coord = {x=self.x, y=self.y}
end
function viewport:free_move()
self.range = nil
self.smooth_adjust = self.fixed_coord
self.fixed_coord = nil
end
function viewport:get()
@@ -33,30 +51,6 @@ function viewport:inside( x, y, w, h )
return result
end
-- 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
function viewport:tile ()
return coords.world_to_tile(self.x, self.y)
end
@@ -67,42 +61,66 @@ end
function viewport:coord2room ()
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: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
if self.range==nil then
if self.smooth_adjust == nil then
self.x = nx
self.y = ny
else
-- viewport lliure després de fixar-lo -> Ajustar suau
self.x = nx
if self.smooth_adjust.x~=nil then
if nx<self.smooth_adjust.x-self.adjust_speed then
self.x=self.smooth_adjust.x-self.adjust_speed
self.smooth_adjust.x=self.smooth_adjust.x-self.adjust_speed
elseif nx>self.smooth_adjust.x+self.adjust_speed then
self.x=self.smooth_adjust.x+self.adjust_speed
self.smooth_adjust.x=self.smooth_adjust.x+self.adjust_speed
elseif math.abs(nx-self.smooth_adjust.x)<self.adjust_speed then
self.smooth_adjust.x = nil
end
end
self.y = ny
if self.smooth_adjust.y~=nil then
if ny<self.smooth_adjust.y-self.adjust_speed then
self.y=self.smooth_adjust.y-self.adjust_speed
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
elseif ny>self.smooth_adjust.y+self.adjust_speed then
self.y=self.smooth_adjust.y+self.adjust_speed
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed
elseif math.abs(ny-self.smooth_adjust.y)<self.adjust_speed then
self.smooth_adjust.y = nil
end
end
if self.smooth_adjust.x == nil and self.smooth_adjust.y == nil then
self.smooth_adjust = nil
end
end
else
-- viewport fixe
self.x = nx
-- moure viewport left - right
if nx<self.fixed_coord.x-self.range.l then
self.x = self.fixed_coord.x-self.range.l
elseif nx>self.fixed_coord.x+self.range.r then
self.x = self.fixed_coord.x+self.range.r
end
self.y = ny
-- moure viewport up - down
if ny<self.fixed_coord.y-self.range.u then
self.y = self.fixed_coord.y-self.range.u
elseif ny>self.fixed_coord.y+self.range.d then
self.y = self.fixed_coord.y+self.range.d
end
end
return self.x, self.y
end