-- Code for bullets! import "CoreLibs/object" import "CoreLibs/graphics" import "CoreLibs/sprites" local gfx = playdate.graphics class("Bullet").extends(gfx.sprite) function Bullet:init(power, friendly) Bullet.super.init(self) self.power = power local size = 1 if power == 1 then size = 2 elseif power == 2 then size = 4 elseif power == 3 then size = 6 elseif power == 4 then size = 10 end local img = gfx.image.new(size, size) gfx.pushContext(img) gfx.fillCircleInRect(0, 0, size, size) gfx.popContext() self:setImage(img) self:setCollideRect(0, 0, self:getSize()) self.collisionResponse = gfx.sprite.kCollisionTypeOverlap local friendly = friendly or true if friendly then self:setGroupMask(0x4) self:setCollidesWithGroupsMask(0x8) self.direction = 1 else self:setGroupMask(0x10) self:setCollidesWithGroupsMask(0x2) self.direction = -1 end end function Bullet:update() self:moveWithCollisions(self.x+self.direction, self.y) end