-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.lua
52 lines (46 loc) · 1.07 KB
/
utils.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
47
48
49
50
51
52
function manhattan(p, q)
assert(#p == #q, 'vectors must have the same length')
local s = 0
for i in ipairs(p) do
s = s + math.abs(p[i] - q[i])
end
return s
end
function key_to_joy(key)
if key == "up" then
return "dpup"
elseif key == "down" then
return "dpdown"
elseif key == "left" then
return "dpleft"
elseif key == "right" then
return "dpright"
elseif key == "1" then
return "a"
elseif key == "2" then
return "b"
elseif key == "3" then
return "x"
elseif key == "4" then
return "y"
else
return nil
end
end
function gamepadConnected()
joysticks = love.joystick.getJoysticks()
return #joysticks > 0
end
function math.Clamp(val, lower, upper)
return math.max(lower, math.min(upper, val))
end
function seconds_to_clock(seconds)
local seconds = tonumber(seconds)
if seconds <= 0 then
return "00:00";
else
mins = string.format("%02.f", math.floor(seconds/60));
secs = string.format("%02.f", math.floor(seconds - mins *60));
return mins..":"..secs
end
end