2023-09-30 00:52:06 +00:00
|
|
|
-- Code for bullets!
|
|
|
|
import "CoreLibs/object"
|
|
|
|
import "CoreLibs/graphics"
|
|
|
|
import "CoreLibs/sprites"
|
|
|
|
|
|
|
|
local gfx <const> = playdate.graphics
|
|
|
|
|
|
|
|
class("Bullet").extends(gfx.sprite)
|
|
|
|
|
|
|
|
function Bullet:init(size, friendly)
|
|
|
|
local img = gfx.image.new(size, size)
|
|
|
|
gfx.pushContext(img)
|
2023-09-30 02:07:02 +00:00
|
|
|
gfx.fillCircleInRect(0, 0, size, size)
|
2023-09-30 00:52:06 +00:00
|
|
|
gfx.popContext()
|
|
|
|
|
|
|
|
Bullet.super.init(self, img)
|
|
|
|
self:setCollideRect(0, 0, self:getSize())
|
|
|
|
|
|
|
|
local friendly = friendly or true
|
|
|
|
if friendly then
|
|
|
|
self:setGroupMask(0x4)
|
|
|
|
self:setCollidesWithGroupsMask(0x9)
|
|
|
|
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
|