-- A superclass for all player and AI-controlled units import "CoreLibs/object" import "CoreLibs/graphics" import "CoreLibs/sprites" local gfx = playdate.graphics class("Entity").extends(gfx.sprite) 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()) -- most entities will be enemies, so we configure this mask by default -- We don't set a collider mask because collision is a bit too variable -- (but we should always include 0x2 and handle player collisions) self:setGroupMask(0x4) end function Entity:damage(amount) if amount < self.armor then return end self.health = math.max(self.health - (amount - self.armor), 0) if self.health == 0 then self:remove() end end