summaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-14 17:37:20 +0800
committerEltrac <hi@guhub.cn>2025-03-14 17:37:20 +0800
commit81e37a7331b1ab00b4ce9bebec768c7abfe163c6 (patch)
tree449bd31ba241d1b0c24f2558a82f9623ee1df878 /objects
parent39fda7fdfb28bc784d42b1fc95d375ab1beefdfe (diff)
feat: purple heart now bounce at a diagonal direction
Diffstat (limited to 'objects')
-rw-r--r--objects/Shot.lua20
1 files changed, 17 insertions, 3 deletions
diff --git a/objects/Shot.lua b/objects/Shot.lua
index cbadabe..e479b2a 100644
--- a/objects/Shot.lua
+++ b/objects/Shot.lua
@@ -70,9 +70,22 @@ function Shot:onContact(other, contact)
if not self.bounced then self.bounced = 0 end
if self.bounced <= data.bouncy then
dieOnThisContact = false
- local dx = other.x - self.x
- local dy = other.y - self.y
- local angle = utils.atan2(dy, dx)
+
+ -- calculate diagonal direction
+ local dx = self.x - other.x
+ local dy = self.y - other.y
+ local angle
+
+ if math.abs(dx) > math.abs(dy) then
+ angle = math.pi / 4
+ else
+ angle = 3 * math.pi / 4
+ end
+
+ if math.random(2) == 1 then
+ angle = -angle
+ end
+
self.physicsBody:setLinearVelocity(math.cos(angle) * config.bullet.speed,
math.sin(angle) * config.bullet.speed)
self.bounced = self.bounced + 1
@@ -86,6 +99,7 @@ function Shot:onContact(other, contact)
end
end
+
if dieOnThisContact then
self:die()
end