From f6ae85dcb13fc449b40e61e6692434968b3dd0f2 Mon Sep 17 00:00:00 2001 From: annabunches Date: Sat, 30 Sep 2023 15:34:29 -0400 Subject: [PATCH] Add new enemy, refactor a bit, add armor. --- src/enemy/ebi.lua | 14 ++++++++++++++ src/{ => enemy}/ika.lua | 4 ++-- src/entity.lua | 7 +++++-- src/main.lua | 19 ++++++++++++++++++- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/enemy/ebi.lua rename src/{ => enemy}/ika.lua (70%) diff --git a/src/enemy/ebi.lua b/src/enemy/ebi.lua new file mode 100644 index 0000000..dc92ba1 --- /dev/null +++ b/src/enemy/ebi.lua @@ -0,0 +1,14 @@ +-- A shrimp-like enemy unit +import "CoreLibs/object" +import "CoreLibs/graphics" +import "CoreLibs/sprites" +import "entity" + +local gfx = 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 diff --git a/src/ika.lua b/src/enemy/ika.lua similarity index 70% rename from src/ika.lua rename to src/enemy/ika.lua index 5bc8905..3026391 100644 --- a/src/ika.lua +++ b/src/enemy/ika.lua @@ -9,6 +9,6 @@ local gfx = playdate.graphics class("Ika").extends(Entity) function Ika:init() - local img = gfx.image.new(30, 30, gfx.kColorBlack) - Ika.super.init(self, img, 25) + local img = gfx.image.new(50, 50, gfx.kColorBlack) + Ika.super.init(self, img, 25, 1) end diff --git a/src/entity.lua b/src/entity.lua index 66c926f..6c701d2 100644 --- a/src/entity.lua +++ b/src/entity.lua @@ -7,9 +7,10 @@ local gfx = 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() diff --git a/src/main.lua b/src/main.lua index ad9e897..9ca2a32 100644 --- a/src/main.lua +++ b/src/main.lua @@ -9,7 +9,8 @@ import "CoreLibs/graphics" import "CoreLibs/sprites" import "CoreLibs/timer" import "kani" -import "ika" +import "enemy/ika" +import "enemy/ebi" local gfx = playdate.graphics @@ -28,6 +29,22 @@ function setup() enemy:moveTo(350, 120) 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() drawBackground()