scenes/levels: add function to know if something is inside the view
This commit is contained in:
parent
c40a4c1678
commit
7d2ed700f7
|
@ -123,3 +123,14 @@ function Level:getVisibleEntities()
|
|||
local visibleThings, len = self:queryRect(camx-64, camy-64, camw+128, camh+128)
|
||||
return visibleThings, len
|
||||
end
|
||||
|
||||
function Level:isInsideView(x, y, w, h, border)
|
||||
local camx, camy, camw, camh = self:getCameraCoord()
|
||||
local border = border or 0
|
||||
if (x + w + border >= camx) and (x < camx + camw + border)
|
||||
and (y + h + border >= camy) and (y < camy + camh + border) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,8 +34,8 @@ function Bullet:update(dt)
|
|||
|
||||
self.life = 1
|
||||
|
||||
local localx, localy = self.camera:cameraCoords(self.x, self.y)
|
||||
if (localx < 0) or (localx > 480) or (localy < 0) or (localy > (272)) or (self.xsp == 0) then
|
||||
local isInsideView = self:isInsideView()
|
||||
if (isInsideView == false) or (self.xsp == 0) then
|
||||
self:destroy()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,8 +35,8 @@ function Debris:update(dt)
|
|||
|
||||
self.life = 1
|
||||
|
||||
local localx, localy = self.camera:cameraCoords(self.x, self.y)
|
||||
if (localx < 0) or (localx > 480) or (localy < 0) or (localy > (272)) or (self.xsp == 0) then
|
||||
local isInsideView = self:isInsideView()
|
||||
if (isInsideView == false) or (self.xsp == 0) then
|
||||
self:destroy()
|
||||
end
|
||||
|
||||
|
|
|
@ -141,6 +141,10 @@ function Entity:getDirection()
|
|||
end
|
||||
end
|
||||
|
||||
function Entity:isInsideView()
|
||||
return self.camera:isInsideView(self.x, self.y, self.w, self.h)
|
||||
end
|
||||
|
||||
function Entity:draw()
|
||||
-- Cette fonction en contient rien par défaut
|
||||
end
|
||||
|
|
|
@ -43,8 +43,8 @@ function Weapon:update(dt)
|
|||
|
||||
self.life = 1
|
||||
|
||||
local localx, localy = self.camera:cameraCoords(self.x, self.y)
|
||||
if (localx < 0) or (localx > 480) or (localy < 0) or (localy > (272)) then
|
||||
local isInsideView = self:isInsideView()
|
||||
if (isInsideView == false) then
|
||||
self:destroy()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue