-- 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) self:setCollidesWithGroupsMask(0x3) local dir = 1 if math.random(2) == 1 then dir = -1 end self.vector = {x=0, y=dir} self:weaponTimer() end function Ebi:update() local collisions = Ebi.super.update(self) for i=1, #collisions, 1 do if collisions[i].other:getGroupMask() == 0x1 then self.vector.y *= -1 end end end function Ebi:weaponTimer() local t = playdate.timer.new(1000, function() local b = Bullet(2, 1, {x=-1, y=0}, 0x2) b:moveTo(self.x - (self.width/2) - 1, self.y) b:add() end ) t.repeats = true end