-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviewport.lua
More file actions
35 lines (29 loc) · 730 Bytes
/
Copy pathviewport.lua
File metadata and controls
35 lines (29 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local Camera = require "camera"
local tilesize = require "tilesize"
local World = require "world"
local Viewport = {}
function Viewport:initialize(x, y, scale)
local camera = Camera(x, y)
camera:zoomTo(scale)
self.camera = camera
self.x = x
self.y = y
self.scale = scale
end
function Viewport:roomConstraint(a, room)
local x, y, w, h = room.x * tilesize, room.y * tilesize,
(room.width + 1) * tilesize, (room.height + 1) * tilesize
if World.aabb(a, x, y, w, h) then
self.camera:lookAt((x + w / 2), (y + h / 2))
end
end
function Viewport:lockToPlayer(x, y)
self.camera:lookAt(x, y)
end
function Viewport:attach()
self.camera:attach()
end
function Viewport:detach()
self.camera:detach()
end
return Viewport