-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggers.lua
46 lines (37 loc) · 1.1 KB
/
triggers.lua
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
--trigger class
Trigger = inherits(Rectangle, {
activator = "player",
action = function() end
})
function Trigger:update(dt)
for _, sprite in pairs(p) do
if sprite.user ~= nil then
if sprite.user == self.activator then
if sprite:collideswithrect(self) then
self:action()
end
end
end
end
end
function Trigger:draw()
if showdebug then Rectangle.draw(self, { r = 1, g = 1, b = 1 }, "line") end
end
--camlock trigger class
CameraLockTrigger = inherits(Trigger, {
})
local camera_lock_trigger_mt = class(CameraLockTrigger)
function CameraLockTrigger:new(x, y, width, height, xlock, ylock)
local o = Rectangle:init(x, y, width, height)
o.xlock = xlock or false
o.ylock = ylock or false
o.action = function()
camera.xlock = o.xlock
camera.ylock = o.ylock
end
local s = setmetatable(o, camera_lock_trigger_mt)
return s
end
function CameraLockTrigger:add(x, y, width, height, xlock, ylock)
table.insert(p, CameraLockTrigger:new(x, y, width, height, xlock, ylock))
end