37 lines
1.0 KiB
Lua
37 lines
1.0 KiB
Lua
local world = require("world")
|
|
|
|
local camera = {
|
|
pan = {
|
|
x = 0,
|
|
y = 0,
|
|
},
|
|
}
|
|
|
|
local expireBelowScreen =
|
|
world:filteredSystem("expireBelowScreen", { position = T.XyPair, expireBelowScreenBy = T.number })
|
|
|
|
local focusPriority = {}
|
|
|
|
cameraPanSystem = world:filteredSystem("cameraPan", { focusPriority = T.number, position = T.XyPair }, function(e, _)
|
|
if e.focusPriority >= focusPriority.priority then
|
|
focusPriority.position = e.position
|
|
end
|
|
end)
|
|
|
|
function cameraPanSystem.preProcess()
|
|
focusPriority.priority = 0
|
|
focusPriority.position = { x = 0, y = 0 }
|
|
end
|
|
|
|
function cameraPanSystem:postProcess()
|
|
camera.pan.x = math.max(0, focusPriority.position.x - 200)
|
|
camera.pan.y = math.min(0, focusPriority.position.y - 120)
|
|
love.graphics.translate(0, -camera.pan.y)
|
|
|
|
for _, entity in pairs(expireBelowScreen.entities) do
|
|
if entity.position.y - (camera.pan.y + 240) > entity.expireBelowScreenBy then
|
|
self.world:removeEntity(entity)
|
|
end
|
|
end
|
|
end
|