summaryrefslogtreecommitdiff
path: root/objects/Shot.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-14 17:31:17 +0800
committerEltrac <hi@guhub.cn>2025-03-14 17:31:17 +0800
commit39fda7fdfb28bc784d42b1fc95d375ab1beefdfe (patch)
treea39bd6dbaff84d0089f83d791faa83001c2256ac /objects/Shot.lua
parente6b2b5e4259d92d4b411f788d1b524671329948a (diff)
feat: purple heart can now bounce
Diffstat (limited to 'objects/Shot.lua')
-rw-r--r--objects/Shot.lua25
1 files changed, 24 insertions, 1 deletions
diff --git a/objects/Shot.lua b/objects/Shot.lua
index 48e5869..cbadabe 100644
--- a/objects/Shot.lua
+++ b/objects/Shot.lua
@@ -1,4 +1,5 @@
local bulletData = require "data.bulletData"
+local Loot = require "objects.loot"
local Shot = {}
Shot.__index = Shot
@@ -39,11 +40,11 @@ end
function Shot:onContact(other, contact)
local sort = other.objectType
+ local data = bulletData[self.type]
local dieOnThisContact = true
-- when contact with enemy, deal damage
if sort == "enemy" then
- local data = bulletData[self.type]
other:takeDamage(self.damage)
other:onHit(self)
if data and data.afterHit then
@@ -63,6 +64,28 @@ function Shot:onContact(other, contact)
dieOnThisContact = false
end
+ -- bouncy heart
+ if sort ~= "player" and data and data.bouncy then
+ -- if heart can still bounce
+ 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)
+ self.physicsBody:setLinearVelocity(math.cos(angle) * config.bullet.speed,
+ math.sin(angle) * config.bullet.speed)
+ self.bounced = self.bounced + 1
+ -- if not, then die or break
+ else
+ dieOnThisContact = true
+ if math.random(3) == 1 then
+ local lootItem = Loot:new("brokenheart", other.x, other.y)
+ table.insert(G.currentRoom.objects.loots, lootItem)
+ end
+ end
+ end
+
if dieOnThisContact then
self:die()
end