Add new enemy, refactor a bit, add armor.

This commit is contained in:
Anna Rose Wiggins 2023-09-30 15:34:29 -04:00
parent 4aa4c129dc
commit f6ae85dcb1
4 changed files with 39 additions and 5 deletions

View file

@ -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()