-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcameras.lua
More file actions
29 lines (21 loc) · 865 Bytes
/
cameras.lua
File metadata and controls
29 lines (21 loc) · 865 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
local cameras = {}
function cameras.windowCamera(camera_window, screen, p)
local camera = {}
function camera.update(dt)
if p.x < screen.x + camera_window.x then
screen.x = p.x - camera_window.x
elseif p.x + p.dx > screen.x + camera_window.x + camera_window.dx then
screen.x = p.x + p.dx - (camera_window.x + camera_window.dx)
end
if p.y < screen.y + camera_window.y then
screen.y = p.y - camera_window.y
elseif p.y + p.dy > screen.y + camera_window.y + camera_window.dy then
screen.y = p.y + p.dy - (camera_window.y + camera_window.dy)
end
end
function camera.windowBox()
return { x = screen.x + camera_window.x, y = screen.y + camera_window.y, dx = camera_window.dx, dy = camera_window.dy }
end
return camera
end
return cameras