Add new enemy, refactor a bit, add armor.

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

14
src/enemy/ebi.lua Normal file
View File

@ -0,0 +1,14 @@
-- A shrimp-like enemy unit
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "entity"
local gfx <const> = playdate.graphics
class("Ebi").extends(Entity)
function Ebi:init()
local img = gfx.image.new(10, 10, gfx.kColorBlack)
Ebi.super.init(self, img, 5)
end

View File

@ -9,6 +9,6 @@ local gfx <const> = playdate.graphics
class("Ika").extends(Entity) class("Ika").extends(Entity)
function Ika:init() function Ika:init()
local img = gfx.image.new(30, 30, gfx.kColorBlack) local img = gfx.image.new(50, 50, gfx.kColorBlack)
Ika.super.init(self, img, 25) Ika.super.init(self, img, 25, 1)
end end

View File

@ -7,9 +7,10 @@ local gfx <const> = playdate.graphics
class("Entity").extends(gfx.sprite) class("Entity").extends(gfx.sprite)
function Entity:init(img, health) function Entity:init(img, health, armor)
Entity.super.init(self, img) Entity.super.init(self, img)
self.health = health or 10 self.health = health or 10
self.armor = armor or 0
self:setCollideRect(0, 0, self:getSize()) self:setCollideRect(0, 0, self:getSize())
@ -20,7 +21,9 @@ function Entity:init(img, health)
end end
function Entity:damage(amount) 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 if self.health == 0 then
self:remove() self:remove()

View File

@ -9,7 +9,8 @@ import "CoreLibs/graphics"
import "CoreLibs/sprites" import "CoreLibs/sprites"
import "CoreLibs/timer" import "CoreLibs/timer"
import "kani" import "kani"
import "ika" import "enemy/ika"
import "enemy/ebi"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
@ -28,6 +29,22 @@ function setup()
enemy:moveTo(350, 120) enemy:moveTo(350, 120)
enemy:add() enemy:add()
enemy = Ebi()
enemy:moveTo(300, 50)
enemy:add()
enemy = Ebi()
enemy:moveTo(300, 100)
enemy:add()
enemy = Ebi()
enemy:moveTo(300, 150)
enemy:add()
enemy = Ebi()
enemy:moveTo(300, 200)
enemy:add()
makeWalls() makeWalls()
drawBackground() drawBackground()