From c6e86ae57442b665d138bdb8bdbd2f7bbd9f5520 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 13 Mar 2025 11:55:28 +0800 Subject: feat: pokobs drop a broken heart when a bullet hits them also add a hook (onHit) to define behavior after a enemy is hit --- objects/Enemy.lua | 6 ++++++ objects/Shot.lua | 1 + 2 files changed, 7 insertions(+) (limited to 'objects') diff --git a/objects/Enemy.lua b/objects/Enemy.lua index c80eb11..6bb3fce 100644 --- a/objects/Enemy.lua +++ b/objects/Enemy.lua @@ -133,6 +133,12 @@ function Enemy:getSticky(duration) self.sticky = duration end +function Enemy:onHit(shot) + if enemyData[self.type] and enemyData[self.type].onHit then + enemyData[self.type].onHit(shot) + end +end + function Enemy:update(dt) self:move(dt) self.frameTimer:update(dt) diff --git a/objects/Shot.lua b/objects/Shot.lua index 0e16f9f..67daa5f 100644 --- a/objects/Shot.lua +++ b/objects/Shot.lua @@ -42,6 +42,7 @@ function Shot:onContact(other, contact) -- when contact with enemy, deal damage if other.objectType == "enemy" then other:takeDamage(self.damage) + other:onHit(self) if bulletData[self.type] and bulletData[self.type].afterHit then bulletData[self.type].afterHit(other.x, other.y, other.type) end -- cgit v1.2.3