Compare commits
2 Commits
392b16e598
...
bbe1d539a4
| Author | SHA1 | Date | |
|---|---|---|---|
| bbe1d539a4 | |||
| 074277187c |
+50
-32
@@ -20,7 +20,8 @@ function viewport.new(_width, _height)
|
|||||||
range = nil, -- rang de moviment quan està fixat {r= , l=, u=, d= }
|
range = nil, -- rang de moviment quan està fixat {r= , l=, u=, d= }
|
||||||
fixed_coord = nil, -- coordenades fixades
|
fixed_coord = nil, -- coordenades fixades
|
||||||
smooth_adjust = nil,
|
smooth_adjust = nil,
|
||||||
adjust_speed = 2
|
adjust_speed = 2,
|
||||||
|
fixed_to_free_position = viewport.fixed_to_free_position
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -66,6 +67,52 @@ function viewport:coord2room ()
|
|||||||
return coords.world_to_room(self.x, self.y)
|
return coords.world_to_room(self.x, self.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function viewport:fixed_to_free_position(nx, ny)
|
||||||
|
local speed_x = self.adjust_speed
|
||||||
|
local speed_y = self.adjust_speed
|
||||||
|
local sm_x = self.smooth_adjust.x
|
||||||
|
local sm_y = self.smooth_adjust.y
|
||||||
|
|
||||||
|
-- print("FIXED TO FREE")
|
||||||
|
-- print(" nx,ny= "..nx.." , "..ny)
|
||||||
|
-- if sm_x~=nil then print(" sm_x= "..sm_x) else print(" sm_x= nil") end
|
||||||
|
-- if sm_y~=nil then print(" sm_y= "..sm_y) else print(" sm_y= nil") end
|
||||||
|
-- print(" sp_x,sp_y= "..speed_x.." , "..speed_y)
|
||||||
|
-- print("")
|
||||||
|
|
||||||
|
-- Ajustar eix X
|
||||||
|
self.x = nx
|
||||||
|
if sm_x~=nil then
|
||||||
|
if math.abs(nx-sm_x)<=speed_x then
|
||||||
|
sm_x = nil
|
||||||
|
else
|
||||||
|
if nx<sm_x-speed_x then speed_x = -speed_x end
|
||||||
|
self.x=sm_x+speed_x
|
||||||
|
sm_x =sm_x+speed_x
|
||||||
|
end
|
||||||
|
-- actualitzar eix smooth x
|
||||||
|
self.smooth_adjust.x = sm_x
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ajustar eix Y
|
||||||
|
self.y = ny
|
||||||
|
if sm_y~=nil then
|
||||||
|
if math.abs(ny-sm_y)<=speed_y then
|
||||||
|
sm_y = nil
|
||||||
|
else
|
||||||
|
if ny<sm_y-speed_y then speed_y = -speed_y end
|
||||||
|
self.y=sm_y+speed_y
|
||||||
|
sm_y =sm_y+speed_y
|
||||||
|
end
|
||||||
|
-- actualitzar eix smooth y
|
||||||
|
self.smooth_adjust.y = sm_y
|
||||||
|
end
|
||||||
|
|
||||||
|
if sm_x == nil and sm_y == nil then
|
||||||
|
self.smooth_adjust = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function viewport:position(x, y)
|
function viewport:position(x, y)
|
||||||
local nx = (x ~= nil) and x or self.x
|
local nx = (x ~= nil) and x or self.x
|
||||||
local ny = (y ~= nil) and y or self.y
|
local ny = (y ~= nil) and y or self.y
|
||||||
@@ -74,39 +121,10 @@ function viewport:position(x, y)
|
|||||||
if self.smooth_adjust == nil then
|
if self.smooth_adjust == nil then
|
||||||
self.x = nx
|
self.x = nx
|
||||||
self.y = ny
|
self.y = ny
|
||||||
|
self.range=nil
|
||||||
else
|
else
|
||||||
-- viewport lliure després de fixar-lo -> Ajustar suau
|
-- viewport lliure després de fixar-lo -> Ajustar suau
|
||||||
local speed_x = self.adjust_speed
|
self:fixed_to_free_position(nx, ny)
|
||||||
local speed_y = self.adjust_speed
|
|
||||||
local sm_x = self.smooth_adjust.x
|
|
||||||
local sm_y = self.smooth_adjust.y
|
|
||||||
self.x = nx
|
|
||||||
if sm_x~=nil then
|
|
||||||
if math.abs(nx-sm_x)<speed_x then
|
|
||||||
sm_x = nil
|
|
||||||
else
|
|
||||||
if nx<sm_x-speed_x then speed_x = -speed_x end
|
|
||||||
self.x=sm_x+speed_x
|
|
||||||
sm_x =sm_x+speed_x
|
|
||||||
end
|
|
||||||
self.smooth_adjust.x = sm_x
|
|
||||||
end
|
|
||||||
|
|
||||||
self.y = ny
|
|
||||||
if sm_y~=nil then
|
|
||||||
if math.abs(ny-sm_y)<speed_y then
|
|
||||||
sm_y = nil
|
|
||||||
else
|
|
||||||
if ny<sm_y-speed_y then speed_y = -speed_y end
|
|
||||||
self.y=sm_y+speed_y
|
|
||||||
sm_y =sm_y+speed_y
|
|
||||||
end
|
|
||||||
self.smooth_adjust.y = sm_y
|
|
||||||
end
|
|
||||||
|
|
||||||
if sm_x == nil and sm_y == nil then
|
|
||||||
self.smooth_adjust = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- viewport fixe
|
-- viewport fixe
|
||||||
|
|||||||
Reference in New Issue
Block a user