40 lines
601 B
Lua
40 lines
601 B
Lua
local m = {}
|
|
|
|
local function rext(a, i)
|
|
i = i - 1
|
|
local v = a[i]
|
|
if v then
|
|
return i, v
|
|
end
|
|
end
|
|
|
|
function m.ipairs_rev(a)
|
|
return rext, a, (#a + 1)
|
|
end
|
|
|
|
function m.between(x, a, b)
|
|
return a <= x and x <= b
|
|
end
|
|
|
|
function m.inside(px, py, x, y, w, h)
|
|
return m.between(px, x, x+w) and
|
|
m.between(py, y, y+h)
|
|
end
|
|
|
|
function m.add_entity(a, x)
|
|
table.insert(a, x)
|
|
if not x.idx then
|
|
x.idx = {}
|
|
end
|
|
x.idx[a] = #a
|
|
end
|
|
|
|
function m.del_entity(a, x)
|
|
table.remove(a, x.idx[a])
|
|
|
|
for i, v in ipairs(a) do
|
|
v.idx[a] = i
|
|
end
|
|
end
|
|
|
|
return m
|