36 lines
1.0 KiB
Lua
36 lines
1.0 KiB
Lua
local gfx <const> = playdate.graphics
|
|
|
|
Camera = {
|
|
pan = {
|
|
x = 0,
|
|
y = 0,
|
|
},
|
|
}
|
|
|
|
expireBelowScreenSystem = filteredSystem("expireBelowScreen", { position = T.XyPair, expireBelowScreenBy = T.number })
|
|
|
|
local focusPriority = {}
|
|
|
|
cameraPanSystem = filteredSystem("cameraPan", { focusPriority = T.number, position = T.XyPair }, function(e, dt)
|
|
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)
|
|
gfx.setDrawOffset(-Camera.pan.x, -Camera.pan.y)
|
|
|
|
for _, entity in pairs(expireBelowScreenSystem.entities) do
|
|
if entity.position.y - (Camera.pan.y + 240) > entity.expireBelowScreenBy then
|
|
self.world:removeEntity(entity)
|
|
end
|
|
end
|
|
end
|