summaryrefslogtreecommitdiff
path: root/objects/Obstacle.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-02-22 10:38:47 +0800
committerEltrac <hi@guhub.cn>2025-02-22 10:38:47 +0800
commit040bc85494b86004167ae323e3b77fcf48654051 (patch)
tree82aeeeb8ad09744519b4c99f706a5ca5102c1018 /objects/Obstacle.lua
parent7a403b57dadc10a81e98f5cf4b68a0128e100695 (diff)
fix: unnatural movement around obstacles
- predict next location based on moving direction - add UP and DOWN to Direction as aliases of TOP and BOTTOM, for moving directions instead of location
Diffstat (limited to 'objects/Obstacle.lua')
-rw-r--r--objects/Obstacle.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/objects/Obstacle.lua b/objects/Obstacle.lua
index fb66611..dc6a944 100644
--- a/objects/Obstacle.lua
+++ b/objects/Obstacle.lua
@@ -24,11 +24,17 @@ function Obstacle:getBorders()
return { left, right, top, bottom }
end
-function Obstacle:isMet(body, currentX, currentY, dv)
+function Obstacle:isMet(body, currentX, currentY, dv, dir)
-- x,y should be the predicted next location of this body
-- dv = speed * dt * direction
- local x = currentX + dv
- local y = currentY + dv
+ local x, y
+ if dir == Direction.LEFT or dir == Direction.RIGHT then
+ x = currentX + dv
+ y = currentY
+ elseif dir == Direction.UP or dir == Direction.DOWN then
+ x = currentX
+ y = currentY + dv
+ end
return self.body:collide(body, self.x, self.y, x, y)
end