summaryrefslogtreecommitdiff
path: root/utils/utils.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-13 20:15:40 +0800
committerEltrac <hi@guhub.cn>2025-03-13 20:15:40 +0800
commitcf1ce9c40716da7883cde90633453aaa82fa9a45 (patch)
treece0edefe4af7cbbd0373f9a4e99aefaa7a0a79cb /utils/utils.lua
parentc80deca77394890e4083724b7d29fea4e54b6be4 (diff)
feat: player now can click right to punch mobs
Diffstat (limited to 'utils/utils.lua')
-rw-r--r--utils/utils.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/utils/utils.lua b/utils/utils.lua
index 9bc0fa7..047434a 100644
--- a/utils/utils.lua
+++ b/utils/utils.lua
@@ -99,3 +99,34 @@ function utils.readObjectList(data, objectName)
end
return list
end
+
+function utils.atan2(y, x)
+ if x > 0 then
+ return math.atan(y / x)
+ elseif x < 0 and y >= 0 then
+ return math.atan(y / x) + math.pi
+ elseif x < 0 and y < 0 then
+ return math.atan(y / x) - math.pi
+ elseif x == 0 and y > 0 then
+ return math.pi / 2
+ elseif x == 0 and y < 0 then
+ return -math.pi / 2
+ else
+ return 0 -- Undefined case (x = 0, y = 0)
+ end
+end
+
+function utils.angleToDirection(angle)
+ local dir
+ if angle >= -math.pi / 4 and angle < math.pi / 4 then
+ dir = Direction.LEFT
+ elseif angle >= math.pi / 4 and angle < 3 * math.pi / 4 then
+ dir = Direction.UP
+ elseif angle >= -3 * math.pi / 4 and angle < -math.pi / 4 then
+ dir = Direction.DOWN
+ else
+ dir = Direction.RIGHT
+ end
+
+ return dir
+end