Implement first enemy, bullet damage and collision.
This commit is contained in:
parent
032cc0a2ed
commit
4aa4c129dc
7 changed files with 82 additions and 26 deletions
28
src/entity.lua
Normal file
28
src/entity.lua
Normal file
|
@ -0,0 +1,28 @@
|
|||
-- A superclass for all player and AI-controlled units
|
||||
import "CoreLibs/object"
|
||||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprites"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
|
||||
class("Entity").extends(gfx.sprite)
|
||||
|
||||
function Entity:init(img, health)
|
||||
Entity.super.init(self, img)
|
||||
self.health = health or 10
|
||||
|
||||
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 always handled by
|
||||
-- other objects (todo: consider player staying perfectly still)
|
||||
self:setGroupMask(0x8)
|
||||
end
|
||||
|
||||
function Entity:damage(amount)
|
||||
self.health = math.max(self.health - amount, 0)
|
||||
|
||||
if self.health == 0 then
|
||||
self:remove()
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue