-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.lua
More file actions
55 lines (44 loc) · 1.11 KB
/
Copy pathcamera.lua
File metadata and controls
55 lines (44 loc) · 1.11 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
camera = {x = 0, y = 0, border_reach = false}
camera.screen = {
width = nil,
height = nil,
area = {
top = nil,
bottom = nil,
left = nil,
right = nil
}
}
local scr = camera.screen
camera.setup = function(x, y)--coords of entity
camera.x, camera.y = x - scr.width / 2, y - scr.height / 2
end
camera.ToScreen = function(x, y)
return x - camera.x, y - camera.y
end
camera.ToGlobal = function(x, y)
return x + camera.x, y + camera.y
end
camera.update = function(x, y)
x, y = camera.ToScreen(x, y)
camera.border_reach = (x <= scr.area.left or x >= scr.area.right) or (y <= scr.area.top or y >= scr.area.bottom)
end
camera.updatePos = function(dx, dy)
camera.x = camera.x + dx
camera.y = camera.y + dy
end
camera.isBorderReached = function()
return camera.border_reach
end
scr.setup = function()
scr.width = love.graphics.getWidth()
scr.height = love.graphics.getHeight()
scr.area.right = scr.width - scr.width / 3
scr.area.left = scr.width / 3
scr.area.top = scr.height / 3
scr.area.bottom = scr.height - scr.height / 3
end
scr.center = function()
return scr.width / 2, scr.height / 2
end
return camera