-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswitch.lua
More file actions
38 lines (32 loc) · 776 Bytes
/
Copy pathswitch.lua
File metadata and controls
38 lines (32 loc) · 776 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
36
37
38
local switch = {}
local mt = { __index = switch }
local setmetatable = setmetatable
local graphics = love.graphics
local rectangle = graphics.rectangle
local abs = math.abs
function switch.new(owner, name, x, ud, gvar)
local instance = {
owner = owner,
name = name,
x = x,
y = owner:y(x),
w = 16,
ud = ud,
gvar = gvar,
status = false
}
return setmetatable(instance, mt)
end
function switch:draw()
local h = self.status and 2 or 8
rectangle('fill', self.x - self.w / 2, self.y - h, self.w, h)
end
function switch:contains(x)
local hw = self.w / 2
return x >= self.x - hw and x <= self.x + hw
end
function switch:overlaps(x, r)
local d = abs(self.x - x)
return d < r + self.w / 2
end
return switch