factorite/util.lua

24 lines
657 B
Lua
Raw Permalink Normal View History

2020-10-04 01:13:34 +00:00
function pointInsideRectangle(x1, y1, x2, y2, w, h)
2020-10-04 01:18:24 +00:00
return x1 > x2 and x1 < (x2 + w) and y1 > y2 and y1 < (y2 + w) -- An Awesome Project
2020-10-04 01:13:34 +00:00
end
function mouseInsideRectangle(x, y, w, h)
2020-10-04 01:18:24 +00:00
local x1, y1 = love.mouse.getPosition()
return pointInsideRectangle(x1, y1, x, y, w, h)
2020-10-04 01:13:34 +00:00
end
function rectangleTouchingRectangle(x1, y1, w1, h1, x2, y2, w2, h2)
2020-10-04 01:18:24 +00:00
return (x1 + w1 > x2 and x1 < x2 + w2) and (y1 + h1 > y2 and y1 < y2 + h2)
2020-10-04 01:13:34 +00:00
end
function getTile(x, y)
2020-10-04 01:18:24 +00:00
return (world[x] or {})[y] or {0}
2020-10-04 01:13:34 +00:00
end
function getCameraTile(cx, cy)
2020-10-04 01:18:24 +00:00
return getTile(math.floor(cx / tilesize), math.floor(cy / tilesize))
2020-10-04 01:13:34 +00:00
end
function s(name) -- sprite
2020-10-04 01:18:24 +00:00
return sprites[name]
2020-10-04 01:13:34 +00:00
end