ee648ecb3f
- Move system-y modules into a systems table
32 lines
838 B
Lua
32 lines
838 B
Lua
local camera = {
|
|
x = 0,
|
|
y = 0,
|
|
halfWidth = 160,
|
|
halfHeight = 90,
|
|
}
|
|
|
|
function camera.update(self, level, target, dt)
|
|
if target then
|
|
self.x = self.x + (target.x - self.x) * 0.5
|
|
self.y = self.y + (target.y - self.y) * 0.5
|
|
end
|
|
|
|
if self.x < self.halfWidth then
|
|
self.x = self.halfWidth
|
|
elseif self.x > level.width * level.tile_width - self.halfWidth then
|
|
self.x = level.width * level.tile_width - self.halfWidth
|
|
end
|
|
|
|
if self.y < self.halfHeight then
|
|
self.y = self.halfHeight
|
|
elseif self.y > level.height * level.tile_height - self.halfHeight then
|
|
self.y = level.height * level.tile_height - self.halfHeight
|
|
end
|
|
end
|
|
|
|
function camera.translate(self)
|
|
love.graphics.translate(-self.x + self.halfWidth, -self.y + self.halfHeight)
|
|
end
|
|
|
|
return camera
|