diff options
| author | Eltrac <hi@guhub.cn> | 2025-02-22 10:25:42 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-02-22 10:25:42 +0800 |
| commit | 7a403b57dadc10a81e98f5cf4b68a0128e100695 (patch) | |
| tree | d0cdb7d82f6a836f1410378be7b522b6a25498d0 /objects/Obstacle.lua | |
| parent | 82cfd1c7281f04fccf4e7a4be3c851ddee7d22ae (diff) | |
chore: use predicted location to detect collision with obstacles
Diffstat (limited to 'objects/Obstacle.lua')
| -rw-r--r-- | objects/Obstacle.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/objects/Obstacle.lua b/objects/Obstacle.lua index abea419..fb66611 100644 --- a/objects/Obstacle.lua +++ b/objects/Obstacle.lua @@ -23,3 +23,12 @@ function Obstacle:getBorders() return { left, right, top, bottom } end + +function Obstacle:isMet(body, currentX, currentY, dv) + -- x,y should be the predicted next location of this body + -- dv = speed * dt * direction + local x = currentX + dv + local y = currentY + dv + + return self.body:collide(body, self.x, self.y, x, y) +end |
