Add new enemy, refactor a bit, add armor.
This commit is contained in:
parent
4aa4c129dc
commit
f6ae85dcb1
14
src/enemy/ebi.lua
Normal file
14
src/enemy/ebi.lua
Normal 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
|
|
@ -9,6 +9,6 @@ local gfx <const> = 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
|
|
@ -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()
|
||||
|
|
19
src/main.lua
19
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 <const> = 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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user