diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-13 20:15:40 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-13 20:15:40 +0800 |
| commit | cf1ce9c40716da7883cde90633453aaa82fa9a45 (patch) | |
| tree | ce0edefe4af7cbbd0373f9a4e99aefaa7a0a79cb /utils | |
| parent | c80deca77394890e4083724b7d29fea4e54b6be4 (diff) | |
feat: player now can click right to punch mobs
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/audio.lua | 3 | ||||
| -rw-r--r-- | utils/utils.lua | 31 |
2 files changed, 33 insertions, 1 deletions
diff --git a/utils/audio.lua b/utils/audio.lua index 91e852e..73f9da4 100644 --- a/utils/audio.lua +++ b/utils/audio.lua @@ -7,7 +7,8 @@ local soundResources = { hitGlass = "hit_glass.wav", levelComplete = "level_complete.wav", warning = "warning.wav", - getsHit = "gets_hit.wav" + getsHit = "gets_hit.wav", + punch = "punch.wav" } local musicResources = { 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 |
