diff options
| author | Eltrac <hi@guhub.cn> | 2025-02-16 10:17:45 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-02-16 10:17:45 +0800 |
| commit | 0787f42e906a34a1f0ebb1ddcef3a239a8b2b636 (patch) | |
| tree | c468e4fbaac7b1ecf43f880be714b17670c4b2d8 /utils/utils.lua | |
| parent | ae1e7c52525d364ba0ef8fe4ed73bdf45c3f2bd1 (diff) | |
refactor: project structure
Diffstat (limited to 'utils/utils.lua')
| -rw-r--r-- | utils/utils.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/utils.lua b/utils/utils.lua new file mode 100644 index 0000000..ce7e8b7 --- /dev/null +++ b/utils/utils.lua @@ -0,0 +1,19 @@ +local utils = {} + +function utils.circlesCollide(x1, y1, r1, x2, y2, r2) + local dx = x2 - x1 + local dy = y2 - y1 + local distanceSquared = dx * dx + dy * dy -- 避免开方,提高性能 + local radiusSum = r1 + r2 + return distanceSquared <= radiusSum * radiusSum +end + +function utils.playerCollideWith(x, y, r) + return utils.circlesCollide(G.player.x, G.player.y, G.player.r, x, y, r) +end + +function utils.randomPosition() + return math.random(love.graphics.getWidth()), math.random(love.graphics.getHeight()) +end + +return utils |
