-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs.lua
More file actions
61 lines (49 loc) · 1.29 KB
/
Copy pathfuncs.lua
File metadata and controls
61 lines (49 loc) · 1.29 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
56
57
58
59
60
61
funcs = {} --helper functions
function funcs.DrawEx(pic, x, y, r, xoff, yoff)
if xoff == nil and yoff == nil then
xoff, yoff = pic:getWidth() / 2, pic:getHeight() / 2
end
if r == nil then
r = 0
end
love.graphics.draw(pic, x, y, r, 1, 1, xoff, yoff)
end
function funcs.BytesToDWord(bytes)
return tonumber(string.format('0x%x%x%x%x', bytes[4], bytes[3], bytes[2], bytes[1]))
end
function funcs.ReadDWord(str, offs)
local bytes = {}
bytes[1] = string.byte(str, offs)
bytes[2] = string.byte(str, offs+1)
bytes[3] = string.byte(str, offs+2)
bytes[4] = string.byte(str, offs+3)
return funcs.BytesToDWord(bytes)
end
function funcs.Distance(x1, y1, x2, y2)
return math.sqrt((x2-x1)^2 + (y2-y1)^2)
end
function funcs.GetImageCenter(img)
return img:getWidth() / 2, img:getHeight() / 2
end
function funcs.GetImageSize(img)
return img:getWidth(), img:getHeight()
end
function funcs.tstr(tbl) --debug function. recursively outputs whats inside a table
local str = '{'
for k, v in pairs(tbl) do
if type(v) == 'table' then
str = str..funcs.tstr(v)
elseif type(v) == 'number' then
str = str..k..':'..tostring(math.floor(v))
else
str = str..k..':'..tostring(v)
end
str = str..';'
end
if str ~= '{' then
str = string.sub(str, 1, -2)
end
str = str..'}'
return str
end
return funcs