Make Ebi move, refactor bullet code to make more logic per-entity type.

This commit is contained in:
Anna Rose Wiggins 2023-09-30 16:02:37 -04:00
parent bb25e255a3
commit 0db42e8c87
4 changed files with 46 additions and 21 deletions

View file

@ -20,13 +20,28 @@ local WEAPON_CHARGE_LOOKUP <const> = {
[3]=50
}
-- size of bullet at each power level
local POWER_SIZE_LOOKUP <const> = {
[1] = 2,
[2] = 4,
[3] = 6,
[4] = 10,
}
-- damage of bullet at each power level
local POWER_DAMAGE_LOOKUP <const> = {
[1] = 1,
[2] = 3,
[3] = 5,
[4] = 10,
}
class("Kani").extends(Entity)
function Kani:init(ui)
local img = gfx.image.new("images/kani.png")
Kani.super.init(self, img, 100)
self.vector = {x=0,y=0} -- movement direction
self:setGroupMask(0x2)
self:setCollidesWithGroupsMask(0xd)
@ -96,7 +111,7 @@ function Kani:fire()
return
end
local bullet = Bullet(self.weaponPower)
local bullet = Bullet(POWER_SIZE_LOOKUP[self.weaponPower], POWER_DAMAGE_LOOKUP[self.weaponPower])
bullet:moveTo(self.x+16, self.y)
bullet:add()
self.weaponPower = 0
@ -122,7 +137,7 @@ end
-- move that crab!
function Kani:update()
local collisions = select(3, self:moveWithCollisions(self.x + self.vector.x, self.y + self.vector.y))
local collisions = Kani.super.update(self)
for i=0, #collisions, 1 do
-- handle player-triggered collisions
end