Add code for repeating waves of enemies, adding intro animations so the enemies can 'fly in', and refactor entity to use a state machine system for more flexibility.

This commit is contained in:
2023-10-03 16:16:19 -04:00
parent 2a2b106df0
commit 001ed4cfa4
8 changed files with 253 additions and 49 deletions

View File

@ -11,15 +11,11 @@ class("Ebi").extends(Entity)
function Ebi:init()
Ebi.super.init(self, gfx.image.new("images/ebi.png"), 5)
self:setCollidesWithGroupsMask(0x3)
local dir = 1
if math.random(2) == 1 then
dir = -1
end
self.vector = geom.vector2D.new(0, dir)
self.type = 'ebi'
end
function Ebi:onReady()
self.weaponTimer = playdate.timer.new(2500,
function()
local b = Bullet(2, 1)
@ -30,8 +26,9 @@ function Ebi:init()
self.weaponTimer.repeats = true
end
function Ebi:update()
local collisions = Ebi.super.update(self)
-- Ebi needs to bounce off the walls
function Ebi:runReady()
local collisions = Ebi.super.runReady(self)
for i=1, #collisions, 1 do
if collisions[i].other:getGroupMask() == 0x1 then
self.vector.dy *= -1
@ -39,7 +36,7 @@ function Ebi:update()
end
end
function Ebi:delete()
Ebi.super.delete(self)
self.weaponTimer:remove()
function Ebi:remove()
Ebi.super.remove(self)
if self.weaponTimer then self.weaponTimer:remove() end
end

View File

@ -12,12 +12,15 @@ class("Ika").extends(Entity)
function Ika:init(target)
Ika.super.init(self, gfx.image.new("images/ika.png"), 25, 1)
self.target = target
self:setCollidesWithGroupsMask(0x2)
self.type = 'ika'
end
function Ika:onReady()
self.weaponTimer = playdate.timer.new(7000,
function()
local b = Bullet(9, 20, self:calculateVector(target))
local b = Bullet(9, 20, self:calculateVector(self.target))
b:moveTo(self.x - (self.width/2) - 1, self.y)
b:add()
end
@ -26,9 +29,12 @@ function Ika:init(target)
end
function Ika:calculateVector(target)
local vec = geom.vector2D.new(0,0)
vec.dx = target.x - self.x
vec.dy = target.y - self.y
local vec = geom.point.new(target:getPosition()) -
geom.point.new(self:getPosition())
return vec:normalized() * 3
end
function Ika:remove()
Ika.super.remove(self)
if self.weaponTimer then self.weaponTimer:remove() end
end