modules/world: simplify limitView() by using utils.math.between()

This commit is contained in:
Kazhnuz 2019-05-02 16:19:28 +02:00
parent 8073951822
commit f1edd118ec

View file

@ -237,24 +237,16 @@ end
function CameraSystem:limitView(id)
local viewx, viewy, vieww, viewh = self:getViewCoordinate(id)
if (viewx < 0) then
self.views.list[id].pos.x = (self.views.width / 2)
end
if (viewy < 0) then
self.views.list[id].pos.y = (self.views.height / 2)
end
local worldw, worldh = self.world:getDimensions()
local posx = self.views.list[id].pos.x
local posy = self.views.list[id].pos.y
local minx = self.views.width / 2
local miny = self.views.height / 2
local maxx = worldw - minx
local maxy = worldh - miny
if ((viewx + vieww) > worldw) then
self.views.list[id].pos.x = worldw - (self.views.width / 2)
end
if ((viewy + viewh) > worldh) then
self.views.list[id].pos.y = worldh - (self.views.height / 2)
end
self.views.list[id].pos.x = utils.math.between(posx, minx, maxx)
self.views.list[id].pos.y = utils.math.between(posy, miny, maxy)
self:computeCamPosition(id)
end