Add new enemy, refactor a bit, add armor.
This commit is contained in:
parent
4aa4c129dc
commit
f6ae85dcb1
4 changed files with 39 additions and 5 deletions
|
@ -7,9 +7,10 @@ local gfx <const> = playdate.graphics
|
|||
|
||||
class("Entity").extends(gfx.sprite)
|
||||
|
||||
function Entity:init(img, health)
|
||||
function Entity:init(img, health, armor)
|
||||
Entity.super.init(self, img)
|
||||
self.health = health or 10
|
||||
self.armor = armor or 0
|
||||
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
|
||||
|
@ -20,7 +21,9 @@ function Entity:init(img, health)
|
|||
end
|
||||
|
||||
function Entity:damage(amount)
|
||||
self.health = math.max(self.health - amount, 0)
|
||||
if amount < self.armor then return end
|
||||
|
||||
self.health = math.max(self.health - (amount - self.armor), 0)
|
||||
|
||||
if self.health == 0 then
|
||||
self:remove()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue